I'm new to GDI+ and I don开发者_JAVA技巧'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 :)
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.
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
精彩评论