我想反转一个 Image 对象。目前我的代码如下所示:
private Image Invert(Image img)
{
var bmpPicture = new Bitmap(img.Width, img.Height);
var iaPicture = new ImageAttributes();
var cmPicture = new ColorMatrix { Matrix00 = -1, Matrix11 = -1, Matrix22 = -1 };
iaPicture.SetColorMatrix(cmPicture);
var gfxPicture = Graphics.FromImage(img);
var rctPicture = new Rectangle(0, 0, img.Width, img.Height);
gfxPicture.DrawImage(img, rctPicture, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, iaPicture);
return bmpPicture;
}
但是,当我运行它并在 a 中显示它时PictureBox
,结果是黑色图像。我在 Windows 8 Release preview 下的 Visual Studio 2012 中运行它。如果有更好的方法来做到这一点,请告诉我。谢谢。