views:

1175

answers:

2

I'm developing a set of applications for use creating games in XNA. Using Graphics.drawImage I can easily draw a preview image from an XNA texture2D object.

Each object, eg Character, Map etc, is made up of a List of parts, each part storing information such as position rotation and texture source. The next step is to render a preview of the entire object instead of just a part.

How would I go about this? Can I just treat Graphics.drawImage as a regular XNA draw call and render the section of the object I want to a bitmap by looping through the List and drawing each item to the bitmap in position and in order? Or does each graphics.DrawImage call destroy the Bitmap it draws to?

A: 

Is this what you're looking for?

   Bitmap bmp = new Bitmap(100, 100);
   Graphics g = Graphics.FromImage(bmp);
   g.DrawImage(Properties.Resources.Foo);
   Bitmap bar = Properties.Resources.Bar;
   bar.MakeTransparent(bar.GetPixel(0, 0));
   g.DrawImage(bar);

As long as the Images are transparent (Which you can do at run-time with calls to Bitmap.MakeTransparent()), you can layer things with multiple calls to DrawImage without them "destroying" the bitmap.

NascarEd
A: 

Sounds about right. I have a set of Texture2D xna objects, each of which stores its path to file. Using Image.FromFile() i use this path to create Image objects then I need to draw sections of the image, using Graphics.DrawImage() and a Rectangle describing the section, to a Graphics object. From here can I just make multiple g.DrawImage() calls in a Back to Front order.

Since Texture2D, and Image for that matter, can cope with transparency and my tex sources are all PNG format, I assume I can use the Image class instead of the Bitmap class and save having to the MakeTransparent call, correct?