如题,C#怎样获取灰度图的灰度值
2个回答
展开全部
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);
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);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我文件循环写进每数字都表示像素值没哪位置表示图像宽我知道文件行数8729列数10458像素数91287882.我知道编码啊办呢
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询