我估计是SetColorMatrix中的catype影响,虽然我用的是VB,估计你能看懂。
Dim Image As Long, Graphics As Long
Dim ImgAttr As Long
Dim Matrix(0 To 4, 0 To 4) As Single
Matrix(0, 0) = -1: Matrix(1, 0) = 0: Matrix(2, 0) = 0: Matrix(3, 0) = 0: Matrix(4, 0) = 0
Matrix(0, 1) = 0: Matrix(1, 1) = -1: Matrix(2, 1) = 0: Matrix(3, 1) = 0: Matrix(4, 1) = 0
Matrix(0, 2) = 0: Matrix(1, 2) = 0: Matrix(2, 2) = -1: Matrix(3, 2) = 0: Matrix(4, 2) = 0
Matrix(0, 3) = 0: Matrix(1, 3) = 0: Matrix(2, 3) = 0: Matrix(3, 3) = 1: Matrix(4, 3) = 0
Matrix(0, 4) = 0: Matrix(1, 4) = 0: Matrix(2, 4) = 0: Matrix(3, 4) = 0: Matrix(4, 4) = 1
GdipCreateBitmapFromHBITMAP PicSource.Image.Handle, 0, Image
GdipCreateFromHDC PicDest.hdc, Graphics
GdipGetImageWidth Image, Width
GdipGetImageHeight Image, Height
GdipCreateImageAttributes ImgAttr
'http://blog.csdn.net/maozefa/archive/2007/12/27/1995949.aspx
GdipSetImageAttributesColorMatrix ImgAttr, ColorAdjustTypeBitmap, True, Matrix(0, 0), 0, 1
GdipDrawImageRectRectI Graphics, Image, 0, 0, Width, Height, 0, 0, Width, Height, UnitPixel, ImgAttr, 0, 0
GdipDisposeImageAttributes ImgAttr
GdipDeleteGraphics Graphics
GdipDisposeImage Image
PicDest.Refresh
原始图像
反色后的结果
可以看到,有些点的效果不对。但是对于打部分图像,效果是没有问题的。
不知道是怎么回事,catype的值为0,1,2我都试过,但是对于这幅图像就是不行。
请您有空能帮我诊断一下吗,谢谢。