,我想做什么?
以下函数应该简单地返回参数"sourceImage“定义的具有更改后的”不透明度“的图像:
public static Image DisableImage(Image sourceImage)
{
Image newImage = new Bitmap(sourceImage);
using (Graphics g = Graphics.FromImage(newImage))
{
using (ImageAttributes imageAttributes = new ImageAttributes())
{
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.Matrix33 = 0.5f;
imageAttributes.SetColorMatrix(colorMatrix);
//Draw the original image on the new image using the color matrix
g.DrawImage(sourceImage, new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, imageAttributes);
}
}
return newImage;
}有什么问题?
返回的图像似乎一点也没有改变。
我试过什么?
如果更改以下行
ColorMatrix colorMatrix = new ColorMatrix();至
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]{
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {Color.Red.R / 255.0f,
Color.Red.G / 255.0f,
Color.Red.B / 255.0f,
0, 1}
});图片上画了一部红色半透明的“电影”,这让我怀疑我在如何使用ColorMatrix时遗漏了一些东西。
任何帮助都是感激的,谢谢!
发布于 2021-08-23 06:54:26
好吧,我自己想出来的。
更改这一行:
Image newImage = new Bitmap(sourceImage);至
Image newImage = new Bitmap(sourceImage.Width, sourceImage.Height);是解决办法。
我可能是在现有图像的基础上画的,这当然不是我想要的。有没有可能删除这个问题?
https://stackoverflow.com/questions/68888240
复制相似问题