Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

cutesiham

HDC and BMP

This topic is 5805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, is there anyway to copy a image from the screen (which is located in hdc) and make it to be .bmp file. just like PrintScreen function when u strike the keyboard button and paste it on Paint. well, if anyone knows, would u mind tell me the concept and and some key function thank u from damian

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
yes.

first you need to create/populate a BITMAPINFOHEADER that''s based upon the GetObject info of the bitmap. the bmi will also need to contain room after it for a palette (RGBQUAD data) if the bitmap color depth is 16 bits or less.

then you''ll need to create a buffer for the bitmap data itself and use GetDIBits to retrieve that data into the buffer and the palette data into the bih RGBQUAD buffer.

then you''ll need to create/populate a BITMAPFILEHEADER.

then binary write to file the bfi, bih (plus palette, if needed), and bits data.

Share this post


Link to post
Share on other sites
HWND winhwnd=GetDesktopWindow();
RECTANGLE rect;
GetWindowRectangle(winhwnd,&rect);
HDC winhdc=GetDC(winhwnd);
HDC temphdc=CreateCompatibleDC(winhdc);
HBITMAP temphbitmap=CreateCompatibleBitmap(winhdc,rect.right,rect.bottom);
HBITMAP old=(HBITMAP)SelectObject(temphdc,temphbitmap);
BitBlt(temphdc,0,0,rect.right,rect.bottom,winhdc,0,0,SRCCOPY);
SeletObject(temphdc,old);

ReleaseDC(winhwnd,winhdc);
DeleteDC(hdctemp);

//now in temphbitmap you have screenshot
SaveBitmap(temphdc,temphbitmap,"c:\\1.bmp");

DeleteObject(temphbitmap);

//SaveBitmap you can found in MSDN, just find file savebmp.c in examples ("julia" -something)

//i made it on fly so dont expect it will work

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yes, thank you everyone, i get the thing done. However...

is there any way to just capture the image (exclude the blank and
unused client area).

i used GetClientRect() to grap the image, however, i need to do some filter work, so any method can be used to just copy the image which partly occupies the client area.

thank you

Share this post


Link to post
Share on other sites
Yes, thank you everyone, i get the thing done. However...

is there any way to just capture the image (exclude the blank and
unused client area).

i used GetClientRect() to grap the image, however, i need to do some filter work, so any method can be used to just copy the image which partly occupies the client area.

thank you

Share this post


Link to post
Share on other sites
well. i get all the work done.
actually i determine the size of the image before writing the bit data to the output file.

thank you.... :-)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!