Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.31 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Bitmap::FromFile returning NULL on x86
  2. HRESULT hr;
  3.     using namespace Gdiplus;
  4.     std::string decodedImage = Base64EncodedImage;  
  5.     DWORD imageSize = decodedImage.length();    
  6.  
  7.     HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, imageSize);
  8.     if (!hMem)
  9.         ErrorExit(TEXT("GlobalAlloc")); //http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
  10.  
  11.     LPVOID pImage = ::GlobalLock(hMem);
  12.     if (!pImage)
  13.         ErrorExit(TEXT("GlobalLock"));
  14.  
  15.     CopyMemory(pImage, decodedImage.c_str(), imageSize);
  16.     IStream* pStream = NULL;
  17.  
  18.     BitmapData* bitmapData = new BitmapData;
  19.     if (::CreateStreamOnHGlobal(hMem, FALSE, &pStream) != S_OK)
  20.         ErrorExit(TEXT("CreateStreamOnHGlobal"));
  21.     else
  22.     {      
  23.         bitmap = Bitmap::FromStream(pStream);   //FAILS on WIN32
  24.         if (!bitmap)
  25.             ErrorExit(TEXT("FromStream"));  
  26.  
  27.         RECT clientRect;
  28.         GetClientRect(hwnd, &clientRect);
  29.  
  30.         bitmapClone = bitmap->Clone(0, 0, clientRect.right, clientRect.bottom, PixelFormatDontCare);
  31.         delete bitmap;
  32.         bitmap = NULL;    
  33.     }
  34.        
  35. bitmap = Bitmap::FromStream(pStream);
  36.        
  37. GdiplusStartupInput gdiplusStartupInput;
  38. ULONG_PTR           gdiplusToken;
  39. // Initialize GDI+.
  40. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  41.        
  42. GdiplusShutdown(gdiplusToken);