C#中的图像绘制问题 [英] Problem with Image drawing in C#

查看:70
本文介绍了C#中的图像绘制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这就是发生的事情.基本上,我只是发现C#将我的图片绘制的大小比原先的预期大10 x 10像素.这是发生了什么事:

因此,我正在通过编写一个简单的头部绘图程序进行探索,该程序可以按箭头键的方向移动和旋转.一切都很好,直到我尝试告诉它停在窗体的边缘为止,它始终会越过边界10像素.

现在我以为自己做错了什么,直到我的代码找不到任何问题,所以我在if条件中加了10并留给了它.

现在这是我发现的时候.我决定画一个矩形,大小为我的图像大小(32 x 30),并在与绘制图像的位置完全相同的位置绘制,发现矩形比表单上的图像小10 x 10.

这是怎么回事?我什至在一个全新的程序中证明了我的理论,以确保我的其他代码都不会以某种方式干扰它:''(

现在我承认,我今天真的很累,只是从午睡中醒来,所以可能会出现愚蠢的错误.

请让我知道会发生什么事,谢谢:)

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 :)

推荐答案

您正在使用什么Graphics.PageUnit?您完全确定它是GraphicsUnit.Pixel吗?
如果没有,请设置!
您使用的是Graphics.DrawImage还是Graphics.DrawImageUnscaled?

关闭主题:为什么Image 32x 30 ?人们通常将32x32用于此类大型应用...
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...


请您分享相关的源代码,以便我们可以看到您在做什么/您在做什么正在做.这样我们就可以提供帮助.
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.


当然,这里的代码是:
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));




第一行是绘制一个具有图像尺寸的矩形,并将其放置在图像所在的位置,第二行是绘制一个比宽度和高度大10x10的矩形,只有这个矩形才能完美地包围图像.

我的问题是C#由于某种原因绘制的图像太大:(

哦,另外,这是我用来将图像绘制到表单上的代码:




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


这篇关于C#中的图像绘制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆