HRESULT SaveImage( BYTE * pBuffer, BITMAPINFOHEADER *bmpInfo)
{
Gdiplus::BitmapData bitmapData;
bitmapData.Width = bmpInfo->biWidth;
bitmapData.Height = bmpInfo->biHeight;
bitmapData.Stride = 3 * bmpInfo->biWidth;
bitmapData.PixelFormat = PixelFormat24bppRGB;
bitmapData.Scan0 = (VOID*)pBuffer;
bitmapData.Reserved = NULL;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
if ( GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) != Gdiplus::Ok )
return E_FAIL;
Gdiplus::Bitmap *pBitmap = new Gdiplus::Bitmap(bmpInfo->biWidth, bmpInfo->biHeight, PixelFormat24bppRGB);
if ( pBitmap->LockBits(&Gdiplus::Rect(0, 0, bmpInfo->biWidth, bmpInfo->biHeight),
Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeUserInputBuf,
PixelFormat24bppRGB, &bitmapData) == Gdiplus::Ok )
{
pBitmap->UnlockBits(&bitmapData);
// actually a wrapper for GdipSaveImageToFile, creates the file but with size 0 kb
// st returns FileNotFound, also tried with differents paths and compressors
Gdiplus::Status st = pBitmap->Save(L"C:\\data.bmp", &Gdiplus::ImageFormatBMP, NULL);
}
delete pBitmap;
Gdiplus::GdiplusShutdown(gdiplusToken);
return S_OK;
}
SaveImage
精选 转载![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章