如何在PictureBox中以1:1显示像素

时间:2022-06-22 15:53:07

I have a bitmap (from a .bmp file) that is actually a small part of a larger screen dump that I took earlier.

我有一个位图(来自.bmp文件),它实际上是我之前采用的较大屏幕转储的一小部分。

Now I want to display that bitmap in a PictureBox control (WinForms), but I have trouble getting it to display at the same ratio as when it was captured originally.

现在我想在PictureBox控件(WinForms)中显示该位图,但是我无法以与最初捕获时相同的比率显示它。

I assume it has something to do with Windows' DPI setting for my monitor, but how can I shortcut that and make the bitmap be displayed exactly as when captured?

我认为它与我的显示器的Windows DPI设置有关,但我如何快捷方式并使位图与捕获时完全一致?

1 个解决方案

#1


1  

I figured it out! The problem was not WinForms, but the horizontal and vertical resolution associated with the displayed bitmap. When copying the part of the original screendump into a new bitmap (the one that is later assigned to the Image property of the PictureBox), the new bitmap had a different (=default) resolution setting. By changing the resolution setting to match the one from the source bitmap (the original screendump), the problem went away!

我想到了!问题不是WinForms,而是与显示的位图相关的水平和垂直分辨率。将原始screendump的一部分复制到新位图(稍后分配给PictureBox的Image属性的位图)时,新位图具有不同的(=默认)分辨率设置。通过更改分辨率设置以匹配源位图(原始screendump)中的分辨率设置,问题就消失了!

#1


1  

I figured it out! The problem was not WinForms, but the horizontal and vertical resolution associated with the displayed bitmap. When copying the part of the original screendump into a new bitmap (the one that is later assigned to the Image property of the PictureBox), the new bitmap had a different (=default) resolution setting. By changing the resolution setting to match the one from the source bitmap (the original screendump), the problem went away!

我想到了!问题不是WinForms,而是与显示的位图相关的水平和垂直分辨率。将原始screendump的一部分复制到新位图(稍后分配给PictureBox的Image属性的位图)时,新位图具有不同的(=默认)分辨率设置。通过更改分辨率设置以匹配源位图(原始screendump)中的分辨率设置,问题就消失了!