Graphics.DrawImage unexpectedly resizing image

痴心易碎 提交于 2019-11-29 10:26:35
   graphic.DrawImage(image, 0, 0);

It's not that strange when you use this overload of DrawImage(). It will try to display the image at the original physical size. Which is affected by the DPI (dots per inch) setting of the video adapter. Very common settings today are 96, 120 and 144 dpi, very easy to change with the Display applet in Windows. These dpi values correspond with 100%, 125% and 150% in the applet.

If you want to make sure this does not happen and you get the exact size in pixels then you'll need to use the DrawImage(image, Rectangle) overload.

Do note that physical size matters. If you ever use your program on a "retina" monitor, that day is getting closer and closer, then that 5x29 pixel image is going to look but like a fleck of dust on that nice display. Making programs DpiAware has been ignored for the past 30 years but it is getting to be very important.

Maybe you have a problem with graphics.DpiX and graphics.DpiY, checks if both properties have the same values in your computer and in the server

Did you save and compared the generated images on both side? This looks a bit like a 24bit/32bit color problem.

What happens if you use this constructor:

public Bitmap( int width, int height, PixelFormat format )

using (Bitmap newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb))

As i read the remarks on MSDN:

Remarks
This constructor creates a Bitmap with a PixelFormat enumeration value of Format32bppArgb.

It shouldn't make any difference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!