I have this piece of code running on a 64-bit version of Windows 7: it allows me to convert the Image view contained in std::string ( Base64EncodedImage ) to GdiPlus::Bitmap :
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; }
But it does not work on Windows 7 32-bit, especially on this line:
bitmap = Bitmap::FromStream(pStream);
It always returns NULL , but I can't figure out how this works on x64, but not on x86. If someone can enlighten me, I will be grateful.
Thanks!
source share