我想在我的应用程序中以"真实大小"显示图像.为此,我需要知道显示器的像素大小.
我知道Windows显示分辨率名义上是96dpi,但出于我的目的,我想要更好的猜测.我知道这些信息可能并不总是可用或准确的(例如较旧的CRT显示器),但我认为LCD显示器的前提是这应该是可能的!
有没有办法获得显示器的像素大小?
有没有办法确定像素大小是否准确?
.NET API是首选(我找不到它们),但Win32也行,我很高兴P/Invoke.
我在Windows窗体应用程序中遇到问题,Bitmap.Save在保存到MemoryStream时失败.问题似乎只是间歇性地出现在一台机器上(到目前为止),而坏消息则出现在客户现场.我无法在机器上进行调试,但是我得到了一个堆栈跟踪,将问题缩小到一行代码.
这是我的代码的精简版本:
byte[] ConvertPixelsToBytes()
{
// imagine a picture class that creates a 24 bbp image, and has
// a method to get an unmanaged pixel buffer.
// imagine it also has methods for getting the width,
// height, pitch
// I suppose this line could return a bad address, but
// I would have expected that the Bitmap constructor would have
// failed if it was
System.IntPtr pPixels = picture.GetPixelData();
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
picture.width(),
picture.height(),
picture.pitch(),
System.Drawing.Imaging.PixelFormat.Format24bppRgb, …Run Code Online (Sandbox Code Playgroud)