Smooth scaling with graphics.DrawImage

I draw several images in a grid. Images are saved as 16x16px pngs.

However, later I decided to increase the grid size to 32x32px.

When I use the following code:

graphics.DrawImage(image, Xdraw, Ydraw, 32, 32); 

where the image is the image downloaded from png, and Xdraw and Ydraw are the upper left corner, which is allowed somewhere above.

The image is slightly blurry, because .DrawImage uses a bicubic (or some other anti-aliasing function) to scale the image. I would like it to smooth, so I can keep hard edges.

Is it possible?

+6
source share
2 answers

I think you need to change the InterpolationMode property of your graphic. Also consider SmoothingMode and CompositingQuality of the Graphics class.

+11
source

Two things can work there.

  • Try experimenting with InterpolationMode on a Graphics object. Unfortunately, from my point of view, I do not know which volume setting works better than the default.
  • Try using ScaleTransform on your graphic (remember to reset when you are done).
+3
source

Source: https://habr.com/ru/post/886368/


All Articles