c++ - Taking screenshots -


i have problem taking screenshots. fine, have problem in resolution 1366x768. bitmap broken , can't open file.

hdc _dc = getwindowdc(okno);  szer_wys(); //ustawia szerokosc wysokosc aktywnego ekranu  dc = createcompatibledc( 0 ); bm = createcompatiblebitmap( _dc, w, h ); selectobject( dc, bm ); stretchblt( dc, 0, 0, w, h, _dc, 0, 0, w, h, srccopy );  getobject( bm, 84, buf ); ddd = getdc( 0 ); dc2 = createcompatibledc( ddd );  tagbitmapinfo bit_info; //tworzy obiekt na strukture  bit_info.bmiheader.bisize = sizeof( bit_info.bmiheader );  //rozmiar struktury bmiheader (40 ) bit_info.bmiheader.biwidth = w; //szerokość bitmapy w pikselac bit_info.bmiheader.biheight = h;  //wysokosc bitmapy w pikselac bit_info.bmiheader.biplanes = 1;   bit_info.bmiheader.bibitcount = 24; //liczba bitów kodujących piksel (rgb) bit_info.bmiheader.bicompression = 0; //0 - brak wewnętrznej kompresji bit_info.bmiheader.bisizeimage = 0;   h_createdib = createdibsection( dc, & bit_info, dib_rgb_colors, & buf, 0, 0 );                 getdibits( dc, bm, 0, h, buf, & bit_info, dib_rgb_colors );   bitmapfileheader bit_header; bit_header.bftype = makeword( 'b', 'm' ); //typ pliku bit_header.bfsize = w * h * 3 + 54; //w * h * 3 kolory + nagłówek  bit_header.bfoffbits = 54;  bitmapinfoheader bit_info_header; bit_info_header.bisize = 40; bit_info_header.biwidth = w; bit_info_header.biheight = h; bit_info_header.biplanes = 0; bit_info_header.bibitcount = 24; bit_info_header.bicompression = 0; bit_info_header.bisizeimage = w * h * 3;   sciezka = obiekt.pobierzpathscreen() +  obiekt.pobierznazwe() + ".bmp";         ofstream plik(sciezka, ios::binary); if(plik.good()) {         plik.write(reinterpret_cast<char*>(&bit_header), sizeof(bit_header));         plik.write(reinterpret_cast<char*>(&bit_info_header), sizeof(bit_info_header));         plik.write(reinterpret_cast<char*>(buf), w*h*3 );  }else cout<<"blad pliku";  plik.close(); 

*szer_wys()* reading screen resolution.

edit

i changed content of szer_wys() this:

void zrzut::szer_wys() {     rect re;     getwindowrect( okno, & re );     w = re.right, h = re.bottom;      while(w%4 != 0)     {             w++;     } } 

and works fine :)

the count of bytes per line in bitmap must multiple of 4. in case

(3*1366)/4=1024,5 not multiple of 4 

you have save line line, padding 2 bytes each line. keep in mind change bisizeimage , bfsize member not width , height of image. can avoid problem if use 32bit per pixel.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -