[Gdiplus]_[Beginner]_[Use interpolation mode to control the zoom quality of the picture]

Scenes

  1. When developing WTL programs, Gdiplusdraw PNGpictures are used. Sometimes you will encounter the following situations. When drawing an original picture with equal width and height, the picture looks clear on the interface, and when the PNGwidth and height are reduced, the picture drawn is obviously jagged. What is the reason?

Description

  1. Use the Gdiplus::Graphicsobject method DrawImageto draw the Rectsource rectangular area of ​​the original image to the target Rect, that is, if the width and height of the target area and the source area are inconsistent, the image will be zoomed and drawn. For example, we have an 256x256icon, and then we need to draw the zoom icon to the upper left corner of the title bar, and the icon of this position not only need 32x32, if you do not have a separate 32x32small icon, we need to call in the big icon DrawImagewhen Specify the width and height of the target area 32x32, so Graphicsthat the icon will be scaled when drawing, so there is no need to create a new one Gdiplus::Bitmapfor drawing.

  2. GraphicsWhen zooming and drawing icons, the Interpolation Modeinterpolation mode determines the quality of zooming. By graphics.SetInterpolationModesetting the interpolation mode, by graphics.GetInterpolationModeobtaining the current interpolation mode.

  3. In the header file <gdiplusenums.h>, the following enumeration constants are optional. InterpolationModeDefaultThe value is the default interpolation mode value, which is equal to InterpolationModeLowQualityand equal to InterpolationModeBilinear. And InterpolationModeHighQualityit is supported by default maximum quality option here because the quality is the best InterpolationModeHighQualityBicubic, so InterpolationModeHighQualitythat is equal InterpolationModeHighQualityBicubic.

    typedef enum InterpolationMode {
          
          
      InterpolationModeInvalid,
      InterpolationModeDefault, // 默认,即等于 InterpolationModeBilinear
      InterpolationModeLowQuality, // 默认,即等于InterpolationModeBilinear
      InterpolationModeHighQuality, // 最高质量,即等于InterpolationModeHighQualityBicubic
      InterpolationModeBilinear, // 双线性插值
      InterpolationModeBicubic, // 双三次插值
      InterpolationModeNearestNeighbor, // 最近邻插值
      InterpolationModeHighQualityBilinear,
      InterpolationModeHighQualityBicubic
    } ;
    
  4. The following code can be used to verify their relationship. The quality of the interpolation mode is the same as their enumeration constant value, from low to high. If you want to set the highest zoom quality, use InterpolationModeHighQualityBicubicparameters. Of course, the higher the quality, the more computing resources are needed. As CPUthe performance improves, this loss can be ignored. If you follow the highest optimization algorithm supported by the system, you can set it InterpolationModeHighQuality, and the current highest value is still equal to InterpolationModeHighQualityBicubic.

    graphics.SetInterpolationMode(InterpolationModeLowQuality);
    auto mode = graphics.GetInterpolationMode(); // mode:InterpolationModeBilinear
    

example

  1. Let's take a look at an 128x128icon that uses the default and highest interpolation mode. The quality is very different. The outer circle of low quality has burrs, and the high quality is soft.

InterpolationModeBilinear(InterpolationModeLowQuality)

figure 1:
Insert picture description here

InterpolationModeHighQualityBicubic(InterpolationModeHighQuality)

figure 2:
Insert picture description here

Original image

Insert picture description here

reference

Using Interpolation Mode to Control Image Quality During Scaling

InterpolationMode enumeration

Guess you like

Origin blog.csdn.net/infoworld/article/details/109316839