HDC and BMP
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
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.
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.
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
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
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement