1

我今天必须在课堂上开始制作拼图/图像拼图,这很好,除了我的图像保持/保持自身重新缩放的事实。

图片本身是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 吗?

预先感谢您的回答

4

1 回答 1

4

这是因为图像的 DPI。您可以使用Graphics.DrawImageUnscaled

e.Graphics.DrawImageUnscaled(Bmp, BmpLoc);

HorizontalResolution您可以使用和VerticalResolution属性检查图像的 DPI(分辨率) 。通常屏幕的分辨率为 96 DPI(每英寸点数)。但是,这在 Windows 中是可配置的。如果图像的分辨率与此不同,则会缩放图像以保持其屏幕尺寸。

于 2013-03-07T22:48:19.250 回答