c# - 为什么我的图像会自动重新缩放?

标签 c#

今天我不得不在类里面开始制作拼图/图像拼图,一切顺利,除了我的图像不断/不断自行重新缩放这一事实。

图像本身是 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/

相关文章:

c# - int' 不包含 'contains' 的定义,并且找不到接受类型为 'contains' 的第一个参数的扩展方法 'int'

c# - 从 LINQ 结果集中访问不同的列

c# - 从 C# 中的另一个页面调用函数

c# - 我是否使用 C# 中的 foreach 以 FIFO 方式获取 Dictionary 中的元素?

c# - 无法在调试中创建 DataCacheFactory 实例

c# - 使用上下文菜单获取数据 GridView 第一个单元格的值

c# - 获取 PropertyInfo 的值

c# - 初始化 C# 委托(delegate)的 "correct"方法是什么?

c# - 如何将字节转换为字符,例如1 -> '1' ?

c# - 如何从包含泛型参数的Type中获取 'basic'类型?