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
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
android 相册 图片 uri格式
感谢stormzhang博客的思路:Android中保存图片的方法可能有如下两种:第一种是自己写方法,如下代码:public static File saveImage(Bitmap bmp) {File appDir = new File(Environment.getExternalStorageDirectory(), "Boohee");if (!appDir.exists()) {
android 相册 图片 uri格式 android 7.1获取存储 android 保存图片 System