I have just started learning XNA. This is my first program that I am writing as a side "fun" project.
I am having trouble drawing a bitmap that gets created to the screen.
I know the bitmap is being created correctly because when I run
bitmap.Save( @"C:\jnk\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp );
it saves the correct bitmap
I am trying to display the image from a class draw function however cannot get anything to appear. I found some sources that used a System.Drawing.Graphics class to create the bitmap and it also showed it drawing it to the screen with
bitmapGraphics.DrawImage( bitmap, new System.Drawing.Point( this.boardXOffset, this.boardYOffset ) );
bitmapGraphics is a Systems.Drawing.Graphics object and the boardOffsets are both 0. I am trying to draw this from a class which is called in the draw function of my main.
However I get nothing, No errors, and no display. I am going to guess that this is because It does not know what object to draw it onto perhaps? But my lack of knowledge in xna... any help would be great.
if it helps at all the main program.cs runs this as its draw function
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear( Color.CornflowerBlue );
BoardGraphicsEngine.Draw();
base.Draw(gameTime);
}
and the draw function in the BoardGraphicsEngine is
public void Draw( )
{
int width = Convert.ToInt32( System.Math.Ceiling( board.pixelWidth ) );
int height = Convert.ToInt32( System.Math.Ceiling( board.pixelHeight ) );
width += 1;
height += 1;
Bitmap bitmap = new Bitmap( width, height );
Graphics bitmapGraphics = Graphics.FromImage( bitmap );
Pen p = new Pen( System.Drawing.Color.Black );
SolidBrush sb = new SolidBrush( System.Drawing.Color.Black );
sb = new SolidBrush( board.boardState.backgroundColor );
bitmapGraphics.FillRectangle( sb, 0, 0, width, height );
... Loop through board and create with a couple calls to
bitmapGraphics.FillPolygon( new SolidBrush( board.hexes[i, j].hexState.BackgroundColor ), board.hexes[i, j].points );
and
bitmapGraphics.DrawPolygon( p, board.hexes[i, j].points );
and
bitmapGraphics.DrawPolygon( p, board.boardState.activeHex.points );
//bitmap.Save( @"C:\jnk\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp );
bitmapGraphics.DrawImage( bitmap, new System.Drawing.Point( this.boardXOffset, this.boardYOffset ) );
bitmapGraphics.Dispose();
bitmap.Dispose();
}
}
The original source for most of this is http://www.codeproject.com/KB/graphics/hexagonal%5Fpart1.aspx but part of the problem may be this example was a windows form and i'm creating an xna project