Drawing PixelFormat32bppPARGB images with GDI+ uses conventional formula instead of premultiplied one

前端 未结 1 1424
独厮守ぢ
独厮守ぢ 2021-01-21 23:30

Here is some minimal code to show an issue:

static const int MAX_WIDTH = 320;
static const int MAX_HEIGHT = 320;

Gdiplus::Bitmap foregroundImg(MAX_WIDTH,MAX_HEI         


        
相关标签:
1条回答
  • 2021-01-21 23:55

    The format of your foreground image doesn't matter (given that it has alpha) because you're setting it to a Gdiplus::Color. Color values are defined as non-premultiplied, so gdiplus multiplies the components by the alpha value when it clears the foreground image. The alternative would be for Color values to have different meaning depending on the format of the render target, and that way lies madness.

    You might be able to do what you intend by setting the source image bits directly, or you might not. Components with values greater than 100% aren't really valid in gdiplus's rendering model, so I'd not be surprised if it caps them during rendering. If you really want this level of control over the rendering, you'll have to lock the bitmap bits and do it yourself.

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