标签:winform style blog http color sp for div 2014
//图片进行灰度处理 //originalImage为原图像 返回灰度图像 private Bitmap GrayImage(Bitmap originalImage) { ImageAttributes imageAttributes = new ImageAttributes(); float[][] matrix = { new float[] {0.299f, 0.299f, 0.299f, 0, 0}, new float[] {0.587f, 0.587f, 0.587f, 0, 0}, new float[] {0.114f, 0.114f, 0.114f, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }; ColorMatrix colorMatrix = new ColorMatrix(matrix); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Bitmap grayHead = new Bitmap(originalImage.Width, originalImage.Height); using (Graphics g = Graphics.FromImage(grayHead)) { g.DrawImage(originalImage, new Rectangle(0, 0, originalImage.Width, originalImage.Height), 0, 0, originalImage.Width, originalImage.Height, GraphicsUnit.Pixel, imageAttributes); } return grayHead; }
效果:
标签:winform style blog http color sp for div 2014
原文地址:http://www.cnblogs.com/MrZivChu/p/grayimage.html