I'm new to GDI+ and I don't know how to draw to an Image. I've a matrix ( game map ) and tiles, Can I create an Image or a Bitmap, then I draw everything on it, so I can work with it likes an Image I load from resources. Thanks so much :)
+1
A:
The GDI+ drawing methods work on an instance of the Graphics class and you can create an instance of Graphics from an image. And then do drawing operations on that object which will draw to your image.
See http://msdn.microsoft.com/en-us/library/5y289054.aspx - It doesn't have a C++ example but the code should be pretty easy to translate.
Also C++ Graphics class reference on how to create instance from Image http://msdn.microsoft.com/en-us/library/ms536159(v=VS.85).aspx
Sijin
2010-05-19 14:17:24
I know about how to create a graphics from an Image. But what I want to do here is draw to an Image. Image map;// Draw tiles to mapGraphics graphic(hdc);graphic.DrawImage(
nXqd
2010-05-19 14:22:12
Cool, that looks right. Are you having issues with drawing the image to the graphics object?
Sijin
2010-05-19 14:35:49
+2
A:
It sounds like the bit you're missing is that you create the Graphics object on a bitmap you've already created or loaded. e.g.
Gdiplus::Bitmap * pDest = new Gdiplus::Bitmap( nWidth, nHeight,
PixelFormat32bppRGB );
Gdiplus::Graphics graphics( pDest );
Then when you actually draw on the graphics object you're drawing on the bitmap. e.g.
graphics.DrawImage( pOtherImage, 0, 0, pOtherImage->GetWidth(),
pOtherImage->GetHeight() );
Now you can manipulate your bitmap however you want.
snowdude
2010-05-19 20:10:06