How to convert graphics to bitmap? in GDI+?

h4ever

Member
Aug 30, 2013
163
0
0
How to convert graphics to bitmap? in GDI+?

Code:
GpGraphics * pG; // pBitmap already contains image/picture
result = Gdiplus::DllExports::GdipGetImageGraphicsContext(pBitmap, &pG);
CLSID pngClsid;    
GetEncoderClsid(L"image/png", &pngClsid);
GpBitmap* pBitmap2;
result = Gdiplus::DllExports::GdipCreateBitmapFromGraphics(60, 60, pG, &pBitmap2);
result = Gdiplus::DllExports::GdipSaveImageToFile(pBitmap2, L"justest.png", &pngClsid, NULL);  // last voluntary? GDIPCONST EncoderParameters* encoderParams
If I comment the line with GdipCreateBitmapFromGraphics, it will save the pucture.
If I use the command GdipCreateBitmapFromGraphics, the image is black, no picture there.
Why the GdipCreateBitmapFromGraphics command does not do what I expect to do?

In every line the result is 0 when debugging.

Code:
result = Gdiplus::DllExports::GdipCreateBitmapFromGraphics(60, 60, pG, &pBitmap2);
always creates blank image
 
Last edited:

cabri

Diamond Member
Nov 3, 2012
3,616
1
81
What does pBitmap2 point to?

Has the bitmap been created?

In your sample, you have only defined the pointer. :(
 

h4ever

Member
Aug 30, 2013
163
0
0
capri,

here is complete code:
http://paste.ofcode.org/34GQSSXar7TSj9WRqzx7Crn

HBitmap contains capture of window (picture).

Here I convert it to bitmap.
Code:
GpBitmap* pBitmap;
int result = Gdiplus::DllExports::GdipCreateBitmapFromHBITMAP(HBitmap, 0, &pBitmap);

Here:
Code:
GpGraphics * pG;
// I create graphics from bitmap
result = Gdiplus::DllExports::GdipGetImageGraphicsContext(pBitmap, &pG);

I need to get the bitmap to graphics because I want to rotate the graphics (the picture of window).

The following code on line 272 is for test only:
Code:
CLSID pngClsid;    
GetEncoderClsid(L"image/png", &pngClsid);
GpBitmap* pBitmap2;
result = Gdiplus::DllExports::GdipCreateBitmapFromGraphics(60, 60, pG, &pBitmap2);

I need to convert the graphics to bitmap and to save it.
Because the output png file contains blank image, it means there is some mistake. I need to get the graphics to image and then to the file. When this will work, I can continue }I will remove the testing code and will rotate the graphics. But I need to make the testing part working to test that the graphics contains the drawings which I do bellow.