Graphics.DrawImage unexpectedly resizing image

后端 未结 3 1943
梦谈多话
梦谈多话 2020-12-19 07:10

I\'ve got some code that takes a png that is a greyscale image with transparency and attempts to create a new image that has a given background colour (looked up from a data

相关标签:
3条回答
  • 2020-12-19 07:50

    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

    0 讨论(0)
  • 2020-12-19 07:59
       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.

    0 讨论(0)
  • 2020-12-19 08:08

    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.

    0 讨论(0)
提交回复
热议问题