根据hbitmap如何得到图片大小或者保存为文件?

来源:百度知道 编辑:UC知道 时间:2024/05/17 00:18:00
我从屏幕上截图下来,得到的是HBITMAP,我怎么样才能得到这张图片?我想用SOCKET把图发送出去,但不知道hbitmap的大小,或者怎么把hbitmap存为bmp文件?hbitmap是这样得到的
hbitmap=CreateCompatibleBitmap(hscrdc,w,h);
holdbit=SelectObject(hmemdc,hbitmap);
BitBlt(hmemdc,0,0,w,h,hscrdc,x,y,0xcc0020);
hbitmap=(HBITMAP*)SelectObject(hmemdc,holdbit);
先谢谢你,但是我还是想得到hbitmap指向的图片,有没有方法?
又遇到个问题,用什么方法可以把图片字节流还原成图片文件保存?

我写过一个 从屏幕上截图到clipboard里 (相当于按print-screen键,或 我这里有一个 按 Alt+print-screen键),然后存为BMP的子程序。你稍作修改(例如改一下存放的文件名,添主程序和函数调用)就可以用。
// ---dib functions 函数原型-----
int GetBytesPerPixel(int depth);
int GetBytesPerRow(int width, int depth);
int GetBitmapBytes(int width, int height, int depth);
void save_clipboard_img_to_bmp();
// ---------函数定义---------
int GetBytesPerPixel(int depth)
{ return (depth==32 ? 4 : 3);
}

int GetBytesPerRow(int width, int depth)
{
int bytesPerPixel = GetBytesPerPixel(depth);
int bytesPerRow = ((width * bytesPerPixel + 3) & ~3);
return bytesPerRow;
}

// bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, bmi.bmiHeader.biBitCount
int GetBitmapBytes(int width, int height, int depth)
{
return height * GetBytesPerRow(width, depth);
}

void save_clipboard_img_to_bmp()
{
char nameout[80];
HANDLE h_bitmap,h_dib;
BITMAPINFO bmi;
HDC hDC;