我需要绘制图像并使此图像的一部分透明。我写了这样的代码:
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通道,但速度较慢。我还能尝试什么?