十四、GDI+实例——木刻效果
木刻滤镜:分析彩色图片中的每一点像素值,如果该点比较亮,将之改为黑色;反之则改白色。亮与不亮的标准在于该点的R、G、B的平均分量值是否达到255/2。
Bitmap bmp = new Bitmap(Application.StartupPath + "//1.jpg");
Graphics g = this.CreateGraphics();
g.TranslateTransform(205, 0);
g.ScaleTransform(0.5f, 0.5f);
int width = bmp.Width;
int height = bmp.Height;
Color colorTemp,color;
int tmpp;
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
color = bmp.GetPixel(i, j);
int avg = (color.R + color.G + color.B) / 3;
if (avg >= 128)
tmpp = 255;
else
tmpp = 0;
colorTemp = Color.FromArgb(255, tmpp, tmpp, tmpp);
bmp.SetPixel(i, j, colorTemp);
}
}
g.DrawImage(bmp, 0, 0);
g.Dispose();
bmp.Dispose();
本人也在学习GDI+,写得比较简单,让高手见笑了。欢迎高手给我指点
QQ:125941562