扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
#ifndef ULONG_PTR #define ULONG_PTR unsigned long* #include "GdiPlus.h" using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib") #endif |
GdiplusStartupInput m_gdiplusStartupInput; ULONG_PTR m_gdiplusToken; |
GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL); |
BOOL MBmpToMImage(CMemFile& cbfBmp, CMemFile& cbfImage, CString strType) |
BOOL MBmpToMImage(CMemFile& cbfBmp, CMemFile& cbfImage, CString strType) { int iBmpSize = cbfBmp.GetLength(); HGLOBAL hMemBmp = GlobalAlloc(GMEM_FIXED, iBmpSize); if (hMemBmp == NULL) return FALSE; IStream* pStmBmp = NULL; CreateStreamOnHGlobal(hMemBmp, FALSE, &pStmBmp); if (pStmBmp == NULL) { GlobalFree(hMemBmp); return FALSE; } BYTE* pbyBmp = (BYTE *)GlobalLock(hMemBmp); cbfBmp.SeekToBegin(); cbfBmp.Read(pbyBmp, iBmpSize); Image* imImage = NULL; imImage = Image::FromStream(pStmBmp, FALSE); if (imImage == NULL) { GlobalUnlock(hMemBmp); GlobalFree(hMemBmp); return FALSE; } USES_CONVERSION; CLSID clImageClsid; GetImageCLSID(A2W("image/"+strType.GetBuffer(0)), &clImageClsid); HGLOBAL hMemImage = GlobalAlloc(GMEM_MOVEABLE, 0); if (hMemImage == NULL) { pStmBmp->Release(); GlobalUnlock(hMemBmp); GlobalFree(hMemBmp); if (imImage != NULL) delete imImage; return FALSE; } IStream* pStmImage = NULL; CreateStreamOnHGlobal(hMemImage, TRUE, &pStmImage); if (pStmImage == NULL) { pStmBmp->Release(); GlobalUnlock(hMemBmp); GlobalFree(hMemBmp); GlobalFree(hMemImage); if (imImage != NULL) delete imImage return FALSE; } imImage->Save(pStmImage, &clJpgClsid); if (pStmImage == NULL) { pStmBmp->Release(); pStmImage>Release(); GlobalUnlock(hMemBmp); GlobalFree(hMemBmp); GlobalFree(hMemImage; if (imImage != NULL) delete imImage; return FALSE; } LARGE_INTEGER liBegin = {0}; pStmImage->Seek(liBegin, STREAM_SEEK_SET, NULL); BYTE* pbyImage = (BYTE *)GlobalLock(hMemImage); cbfImage.SeekToBegin(); cbfImage.Write(pbyImage, GlobalSize(hMemImage)); if (imImage != NULL) delete imImage; pStmBmp->Release(); pStmImage->Release(); GlobalUnlock(hMemBmp); GlobalUnlock(hMemImage); GlobalFree(hMemBmp); GlobalFree(hMemImage); return TRUE; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者