C# Painting PNGs

Started by
1 comment, last by AlysiumX 12 years, 8 months ago
So I have been creating a stage editor using winforms. Instead of using PictureBoxes for tiles, I decided to over ride the paint method and load it in that way. Problem is when I load in my images, they go from 32x32 to 41x41. I believe it might have something to do with them being png format but i'm not entirely sure, anyone else run into this problem?

Heres the code I am using.


Image blankTile = Image.FromFile(Application.StartupPath + "/Textures/T_Blank.png");


//Paint of main panel.
int[,] level = new int[,]
{
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
private void pnlMain_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;


for (int y = 0; y < level.GetUpperBound(1) + 1; y++)
{
for (int x = 0; x < level.GetUpperBound(0) + 1; x++)
{
if (level[x, y] == 0)
{
Point imageLocation = new Point(blankTile.Width * x, blankTile.Height * y);
g.DrawImage(blankTile, imageLocation);
}
}
}
}



Also ideally I would love to embed an "xna frame" in the form, something similar to what you get when you start up an xna project, but in a panel. Is there any way to do this?

Any help would be great thanks.
Advertisement
I've had that scaling issue before. I don't recall how I fixed it. I'll look into it and see if I can't remember. In the meantime someone else may have the information already.

Also, regarding your desire to embed XNA into a WinForm, Microsoft created a sample that shows you how to do this: http://create.msdn.c...nforms_series_1

(EDIT: I think you can fix the scaling issue by calling Graphics.ScaleTransform() and passing 1 to the parameters. If that doesn't work, you can try calling Graphics.ResetTransform() before trying to draw.)
Scaling didnt work, and that sample just doesn't seem very clear to me. I am beginning to wonder if it would be easier to implement slimdx or something to get the panel I am looking for.

This topic is closed to new replies.

Advertisement