今天我不得不在类里面开始制作拼图/图像拼图,一切顺利,除了我的图像不断/不断自行重新缩放这一事实。
图像本身是 300*300,但是当运行代码时它变成了 192*192,即使我使用图像自己的尺寸来声明尺寸。
代码组成:
public partial class Form1 : Form
{
private Bitmap Bmp;
private Point BmpLoc;
int x = 0, y = 0;
public Form1()
{
InitializeComponent();
this.Paint += new System.Windows.Forms.PaintEventHandler(Form1_Paint);
}
private void showButton_Click(object sender, EventArgs e)
{
Bmp = new Bitmap("C:\\Users\\Admin\\Desktop\\img.png");
BmpLoc = new Point(0, 0);
Rectangle R = new Rectangle(BmpLoc, Bmp.Size);
int noot = Bmp.Size.Height;
label3.Text = noot.ToString();
this.Invalidate(R);
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (Bmp != null)
{
e.Graphics.DrawImage(Bmp, BmpLoc);
}
}
如您所见,它采用位图大小作为矩形的大小,所以它不应该只显示 300*300 吗?
预先感谢您的回答
最佳答案
这是因为图像的 DPI。您可以使用 Graphics.DrawImageUnscaled
:
e.Graphics.DrawImageUnscaled(Bmp, BmpLoc);
您可以使用 HorizontalResolution
检查图像的 DPI(分辨率)和 VerticalResolution
特性。通常屏幕的分辨率为 96 DPI(每英寸点数)。但是,这在 Windows 中是可配置的。如果图像的分辨率不是这个分辨率,图像将被缩放以保持其屏幕大小。
关于c# - 为什么我的图像会自动重新缩放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15283267/