大家帮帮忙,谢谢了
HANDLE hData = Bitmap2Dib(hbitmap, wbitcount); // Hbitmap convert to bitmap
UINT nSize = GlobalSize(hData);
CMemFile* fo= new CMemFile((BYTE *)GlobalLock(hData), nSize);
// 内存文件转化为流
IStream* pStmBmp = NULL;
int iBmpSize = fo->GetLength();
HGLOBAL hMemBmp = GlobalAlloc(GMEM_FIXED, iBmpSize);
if (hMemBmp == NULL)
{
return FALSE;
}
CreateStreamOnHGlobal(hMemBmp, FALSE, &pStmBmp);
if (pStmBmp == NULL)
{
GlobalFree(hMemBmp);
return false;
}
HRESULT stat;
CImage *image = new CImage();
image->Create(bitmap.bmWidth, bitmap.bmHeight, wbitcount);
// Load IStream Fail
HRESULT hResult = image->Load(pStmBmp);
if(S_OK != hResult)
{
return false;
}
stat = image->Save(lpfilename, ImageFormatJPEG);
if(S_OK != stat)
{
return false;
}
pStmBmp->Release();
delete image;
1,我想把HBITMAP在内存中转化成为jpg格式的图像文件保存。结果在HRESULT hResult = image->Load(pStmBmp); load IStream的时候出错,不知道是什么原因?
2,我看MSDN上说Load的参数是pStream
A pointer to a stream containing the name of the image file to load.
我的指针里只是包含了图像信息并没有保存图像的名字,不知道在流里应该怎样加图像的名字?
------解决方案--------------------------------------------------------
流中没有数据
HGLOBAL hMemBmp = GlobalAlloc(GMEM_FIXED, iBmpSize);
if (hMemBmp == NULL)
{
return FALSE;
}
CreateStreamOnHGlobal(hMemBmp, FALSE, &pStmBmp);
另外用gdi+ 简单多了
------解决方案--------------------------------------------------------
GDI+
------解决方案--------------------------------------------------------
GDI+应该可以
------解决方案--------------------------------------------------------
直接用COleStreamFile就好了