Non-Smooth Upscaling with graphics.DrawImage

2019-06-18 04:30发布

I am drawing some images in a grid. The images are saved as 16x16px pngs.

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

When I use the following code:

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

where image is an Image loaded from a png, and Xdraw and Ydraw are the top left corner decided somewhere above.

The image is slightly blurry as .DrawImage uses bicubic(or some other smoothing function) to upscale the image. I would like it to turn the smoothing off, so I can preserve the hard edges.

Is this possible?

2条回答
霸刀☆藐视天下
2楼-- · 2019-06-18 04:55

There's two things that might work.

  • Try to experiment with the InterpolationMode property on your Graphics object. Unfortunately, off the top of my head, I don't know which setting woud work better than the default.
  • Try using a ScaleTransform on your Graphics object (an remember to reset it when you're done).
查看更多
▲ chillily
3楼-- · 2019-06-18 05:17

I think you should change InterpolationMode property of your graphics. Aslo take a look into SmoothingMode and CompositingQuality of Graphics class.

查看更多
登录 后发表回答