mythma
彩色图转换为灰度图公式很简单:
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);
885

被折叠的 条评论
为什么被折叠?



