Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay so here's what's going on. Basically, I just discovered that C# is drawing my Images 10 x 10 pixels bigger than they're supposed to be. Here's what happened:

So I was exploring by making a simple program of a drawing of a head that moves and turns in the direction you press an arrow key. Everything was fine until I tried telling it to stop at the edges of the form, it would always go 10 pixels past the border.

Now I assumed I was doing something wrong until I couldn't find anything wrong with my code so I just added 10 to my if conditions and left it at that.

Now here's when I found out. I decided to draw a rectangle the size of my image (32 x 30), and draw it in the exact same spot that my image is drawn in, and I discovered that my rectangle is 10 x 10 smaller than my image on the form.

What's going on? I even proved my theory in a fresh program to make sure none of my other code is somehow interfering with it :'(

Now I'll admit, I've been REALLY tired today and I just woke up from a nap, so stupid errors may be occurring.

Please let me know what could be happening guys, thanks in advance :)
Posted
Updated 8-Oct-10 10:44am
v3

What Graphics.PageUnit are you using? Are you absolutely sure it's GraphicsUnit.Pixel?
If not, set it!
Are you using Graphics.DrawImage or Graphics.DrawImageUnscaled?

Off topic: Why is the Image 32x30? People ususlly use 32x32 for something this big...
 
Share this answer
 
v4
Would you please share the relevant source code so we can see what you're doing / how you're doing it. Then we may be able to help.
 
Share this answer
 
Sure, here's the code:
g.DrawRectangle(new Pen(Color.Black), new Rectangle(an.getCharHeadLoc().X, an.getCharHeadLoc().Y, an.getCurHeadPic().Width, an.getCurHeadPic().Height));

g.DrawRectangle(new Pen(Color.Black), new Rectangle(an.getCharHeadLoc().X, an.getCharHeadLoc().Y, an.getCurHeadPic().Width + 10, an.getCurHeadPic().Height + 10));



The first line is me drawing a rectangle with the dimensions of the image, and placing it where the image is located, and the second line is me drawing a rectangle 10x10 bigger than the width and the height, and only this rectangle surrounds the image perfectly.

My problem is that C# is drawing the image too big for some reason :(

Oh, additionally, here's the code I'm using to draw the image onto the form:
g.DrawImage(an.getCurHeadPic(), an.getCharHeadLoc())
 
Share this answer
 
v3
Comments
Toli Cuturicu 13-Oct-10 10:51am    
Fake answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900