Click to See Complete Forum and Search --> : Saving an image file to a directory with GDI+


Fromethius
July 3rd, 2007, 04:40 PM
Hello everyone and thank you for taking the time to read my post

I am running Visual C++ 2005 and I'm having some trouble with GDI+.


I have two bitmaps:


Bitmap* pngFrame;
Bitmap* pngEmblem;


I initialized them in a function I use, and I can display them no problem like this:

PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
Gdiplus::Graphics* gfx = new Gdiplus::Graphics(ps.hdc);
gfx->DrawImage(pngFrame, 80, 12);
gfx->DrawImage(pngEmblem, 80 + ((17 - (INT)pngEmblem->GetWidth()) / 2), 12 + ((17 - (INT)pngEmblem->GetHeight()) / 2));
delete gfx;
EndPaint(hwnd, &ps);



Now, that works all fine and dandy. However, in another event, when the user clicks a button. I would like to draw the pngFrame, draw the pngEmblem on top of it, and then save it as one picture.

For example (pseudocode):


gfx->DrawImage(pngFrame);
gfx->DrawImage(pngEmblem);
gfx->SaveTo(C:\\picture.png);



They are PNG files so it handles the transparency automatically. But yea, can I get some help with this one?

Boris K K
July 4th, 2007, 08:22 AM
Were you looking for

Bitmap * pbmp = new Bitmap(width, height, pixel_format);
Graphics * pgfx = new Graphics(pbmp);
// Do some drawing with pgfx
pgfx->Flush(FlushIntentionSync); // Probably not needed
pbmp->Save(...);
// Cleanup