C#中GDI+可以画灰度图么,用什么语句啊

jht_1992 2015-04-14 03:17:01
就是画一幅黑白图,求大神解答
...全文
327 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jht_1992 2015-04-15
  • 打赏
  • 举报
回复
谢谢各位,这个问题已经解决了
dylike 2015-04-15
  • 打赏
  • 举报
回复
自带函数 controlpaint.drawdisableimage
於黾 2015-04-14
  • 打赏
  • 举报
回复
灰度图和黑白图不是一个玩意吧? 黑白图是二值图像啊 你画的时候指定颜色别用彩色,只用黑色,白色,灰色,不就得了
assky124 2015-04-14
  • 打赏
  • 举报
回复

Bitmap bmp = new Bitmap(100, 100);
using (Graphics g = Graphics.FromImage(bmp))
{
g.FillEllipse(Brushes.Red, new Rectangle(0, 0, 80, 80));
g.FillRectangle(new SolidBrush(Color.FromArgb(128, Color.Green)), new Rectangle(20, 20, 80, 80));
}
e.Graphics.DrawImage(bmp, new Point(10, 10));

//简单的
ControlPaint.DrawImageDisabled(e.Graphics, bmp, 120, 10, Color.White);

//用颜色矩阵
System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
float[][] colorMatrixElements = {
new float[] {.33f, .33f, .33f, 0, 0}, // r = (r+g+b)/3
new float[] {.33f, .33f, .33f, 0, 0}, // g = (r+g+b)/3
new float[] {.33f, .33f, .33f, 0, 0}, // b = (r+g+b)/3
new float[] {0, 0, 0, 1, 0}, // alpha scaling factor of 1
new float[] {0, 0, 0, 0, 1}}; //
System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements);
attr.SetColorMatrix(matrix);
e.Graphics.DrawImage(bmp, new Rectangle(10, 120, 100, 100), 0, 0, 100, 100, GraphicsUnit.Pixel, attr);


wjq 2015-04-14
  • 打赏
  • 举报
回复
你取RGB三个通道之一为基准。把另外2个通道的值改为与基准值相同,得到的就是灰度了。你不论用什么方法(保留一个通道,或者平均三个通道),把每个像素RGB三个通道的值改的一样,得到的就是“灰度”图像。
相关推荐
发帖
C#

10.9w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2015-04-14 03:17
社区公告

让您成为最强悍的C#开发者