Sign in to follow this  

C# Painting PNGs

This topic is 2322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

[code]
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);
}
}
}
}
[/code]


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.

Share this post


Link to post
Share on other sites
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: [url="http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1"]http://create.msdn.c...nforms_series_1[/url]

(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.)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this