作者del680202 (飘落的樱花)
看板C_Sharp
标题[问题] 请问图片模糊化
时间Wed Aug 22 20:07:55 2007
之前有找到演算法
说让每个像素等於他上下左右像素的RGB的平均值
for (int x=1;x<width-1;x++)
{
for (int y=1;y<height-1;y++)
{
this[x,y] = Color.FromA
(
this[x+1,y].R
+ this[x-1,y].R +
this[x,y+1].R
+ this[x,y-1].R +
this[x,y].R)/5,
(
this[x+1,y].G
+ this[x-1,y].G +
this[x,y+1].G
+ this[x,y-1].G +
this[x,y].G)/5,
(
this[x+1,y].B
+ this[x-1,y].B +
this[x,y+1].B
+ this[x,y-1].B +
this[x,y].B)/5);
}
}
但是这种做法太耗时间了 1024*768的图片就不知道要花多久
後来小弟有找到比较快的方法 就是用指标的方式去巡
BitmapData bmData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width,
bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe {
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - bitmap.Width * 3;
int nWidth = bitmap.Width * 3;
byte b = p[0];
for (int y = 1; y < bitmap.Height; ++y)
{
for (int x = 0; x < nWidth; ++x)
{
p[0]=b;
++p;
}
p += nOffset;
}
}
bitmap.UnlockBits(bmData);
但是这种方法没办法指定他上下左右像素的RGB值
请问用第2种方法要怎麽做到图片模糊化的效果
小弟搜google都只有反色差 灰阶 跟打光的处理而已...~"~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.217.244.46