我需要绘制图像并使该图像的一部分透明。我写这样的代码:
graphics.SetClip(&nonTransparentRegion);
graphics.DrawImage(pImage, dstRect, srcRect, Gdiplus::UnitPixel);
Gdiplus::ColorMatrix colorMatrix;
for (int i = 0; i < 5; ++i)
for (int j = 0; j < 5; ++j)
colorMatrix.m[i][j] = Gdiplus::REAL(i == j);
colorMatrix.m[3][3] = 0.5;
Gdiplus::ImageAttributes imageAttr;
imageAttr.SetColorMatrix(&colorMatrix);
graphics.SetClip(&transparentRegion);
graphics.DrawImage(pImage, dstRect, srcRect, Gdiplus::UnitPixel, &imageAttr);
它工作正常,但它太慢了。我尝试使用 Bitmap.lockBits 并直接为图像更改 alpha 通道,但速度较慢。我还能尝试什么?