C#彩色图片灰度化算法介绍
来源:互联网 发布:学编程书籍推荐 编辑:程序博客网 时间:2024/05/21 07:01
public static Bitmap MakeGrayscale(Bitmap original)
{
//create a blank bitmap the same size as original
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
//get a graphics object from the new image
Graphics g = Graphics.FromImage(newBitmap);
//create the grayscale ColorMatrix
System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(
new float[][]
{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
//create some image attributes
System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
//set the color matrix attribute
attributes.SetColorMatrix(colorMatrix);
//draw the original image on the new image
//using the grayscale color matrix
g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
//dispose the Graphics object
g.Dispose();
return newBitmap;
}
{
//create a blank bitmap the same size as original
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
//get a graphics object from the new image
Graphics g = Graphics.FromImage(newBitmap);
//create the grayscale ColorMatrix
System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(
new float[][]
{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
//create some image attributes
System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
//set the color matrix attribute
attributes.SetColorMatrix(colorMatrix);
//draw the original image on the new image
//using the grayscale color matrix
g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
//dispose the Graphics object
g.Dispose();
return newBitmap;
}
0 0
- C#彩色图片灰度化算法介绍
- java 彩色图片变为灰色,即图片灰度化
- 将彩色图片转为灰度图
- 将彩色图片转成灰度图片
- C#彩色图像灰度化算法
- c# 彩色图片变为黑白图片
- C#图像的灰度化处理:提取像素法介绍
- 用Java对彩色图片进行灰度变换
- 用Java对彩色图片进行灰度变换
- 彩色图片转换为灰度图(方法)
- 如何把彩色图片变成灰度图片-GDI+
- canvas 将彩色图片变成灰度图片
- android opencv 将彩色图片转成灰度图
- ios 彩色图片转换成灰度图片
- CSS把彩色图片变为灰度图片
- word中将彩色图片转为灰度图
- 将彩色图片转化为灰度图
- iOS 彩色图片置灰,灰度图片
- C#事件(event)解析
- CentOS SSH安装和配置
- Smali语法介绍
- Hadoop的MapReduce函数的执行的过程
- SoC嵌入式软件架构设计之二:没有MMU的CPU实现虚拟内存管理的设计方法
- C#彩色图片灰度化算法介绍
- *dev=filp->private_data;这一句的理解
- hdu 1175连连看
- jQuery多级联动多选框
- 黑马程序员_HTML
- 递归与非递归实现二叉树的遍历
- linux设备模型,bus,device,driver,实验遇到的问题
- cpu load measurement
- C++静态成员函数小结