
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 1.31 KB | hits: 17 | expires: Never
Bitmap::FromFile returning NULL on x86
HRESULT hr;
using namespace Gdiplus;
std::string decodedImage = Base64EncodedImage;
DWORD imageSize = decodedImage.length();
HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, imageSize);
if (!hMem)
ErrorExit(TEXT("GlobalAlloc")); //http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
LPVOID pImage = ::GlobalLock(hMem);
if (!pImage)
ErrorExit(TEXT("GlobalLock"));
CopyMemory(pImage, decodedImage.c_str(), imageSize);
IStream* pStream = NULL;
BitmapData* bitmapData = new BitmapData;
if (::CreateStreamOnHGlobal(hMem, FALSE, &pStream) != S_OK)
ErrorExit(TEXT("CreateStreamOnHGlobal"));
else
{
bitmap = Bitmap::FromStream(pStream); //FAILS on WIN32
if (!bitmap)
ErrorExit(TEXT("FromStream"));
RECT clientRect;
GetClientRect(hwnd, &clientRect);
bitmapClone = bitmap->Clone(0, 0, clientRect.right, clientRect.bottom, PixelFormatDontCare);
delete bitmap;
bitmap = NULL;
}
bitmap = Bitmap::FromStream(pStream);
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
GdiplusShutdown(gdiplusToken);