http://www.cppblog.com/mythma/archive/2005/11/16/1147.html
由彩色到黑白
彩色图转换为灰度图公式很简单:
Y=0.3RED+0.59GREEN+0.11 Blue
用GDI+实现的方式由两种:
1. 直接用上述公式修改象素点
2. 用ColorMatrix。
下面是用ColorMatrix实现示例:
using namespace Gdiplus;
Image img(wszFileName);
Graphics graphics(GetDC()->GetSafeHdc());
ColorMatrix cm= {0.3f, 0.3f, 0.3f, 0, 0,
0.59f,0.59f,0.59f,0, 0,
0.11f,0.11f,0.11f,0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1};
ImageAttributes ia;
ia.SetColorMatrix(&cm);

float x = (float)img.GetWidth();
float y = (float)img.GetHeight();
graphics.DrawImage(&img,
RectF(0.0f,0.0f,x,y,
0.0f,0.0f,x,y,
UnitPixel,
&ia);

程序下载
由彩色到黑白
彩色图转换为灰度图公式很简单:
Y=0.3RED+0.59GREEN+0.11 Blue
用GDI+实现的方式由两种:
1. 直接用上述公式修改象素点
2. 用ColorMatrix。
下面是用ColorMatrix实现示例:
using namespace Gdiplus;
Image img(wszFileName);
Graphics graphics(GetDC()->GetSafeHdc());
ColorMatrix cm= {0.3f, 0.3f, 0.3f, 0, 0,
0.59f,0.59f,0.59f,0, 0,
0.11f,0.11f,0.11f,0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1};
ImageAttributes ia;
ia.SetColorMatrix(&cm);
float x = (float)img.GetWidth();
float y = (float)img.GetHeight();
graphics.DrawImage(&img,
RectF(0.0f,0.0f,x,y,
0.0f,0.0f,x,y,
UnitPixel,
&ia);程序下载
ColorMatrix cm
浙公网安备 33010602011771号