如何使用alpha混合在GDI +中绘制emf / wmf图像?

时间:2018-04-19 09:29:21

标签: c++ gdi+

我使用GDI+ Graphics.DrawImage()方法在我的应用程序中绘制元文件图像(emf / wmf)。此方法允许通过ImageAttributes设置颜色矩阵。我使用颜色矩阵来执行图像alpha混合(绘制半透明图像),如下所示:

const auto alphaPercent = 0.5f
ColorMatrix colorMatrix = { 
  1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
  0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
  0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
  0.0f, 0.0f, 0.0f, alphaPercent, 0.0f,
  0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};

ImageAttributes imageAttributes;
imageAttributes.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeDefault);

pGraphics->DrawImage(pImageToDraw,imagePosition, 0.f, 0.f, sourceWidth, sourceHeight, UnitPixel, &imageAttributes);

此方法非常适用于位图,但不适用于emf元文件。 将ColorAdjustTypeDefault更改为ColorAdjustTypePenColorAdjustTypeBrush并不会有帮助。

示例 GDI +结果: enter image description here

但应该是(alpha = 50%): enter image description here

如何使用alpha混合在GDI +中绘制元文件图像?

0 个答案:

没有答案
相关问题