不知道C#有没有前辈做过锐化。
flickr的锐化效果非常棒的说。
flickr的锐化效果非常棒的说。
解决方案 »
- 吧exal导入数据库
- c#建立神经网络计算库?
- 请教一下,在一个窗口用委托事件更新另外一个窗口的combox的问题
- 如何动态设置特性(Attributes)?
- visio 2003 反向工程生成类图
- 以UDP方式实现的P2P,客户端是监听服务器的ip和端口还是监听本地的ip和端口?
- 关于ajax中post请求 与 jquery中的post请求
- 我想问一问有没有关于C#的源代码
- winform 表单的录入 修改 打印
- 在C#窗体应用中,怎样调用DOS命令(eg:net ..)?
- (急切求助)如何把DataTable中数据按行存储到XML?(在线等)
- 如何用C#来实现类似51job上的模块任意拖动的功能,在线等!
public void SetColorFilter(ColorFilterTypes colorFilterType)
{
Bitmap temp = (Bitmap)_currentBitmap;
Bitmap bmap = (Bitmap)temp.Clone();
Color c;
for (int i = 0; i < bmap.Width; i++)
{
for (int j = 0; j < bmap.Height; j++)
{
c = bmap.GetPixel(i, j);
int nPixelR = 0;
int nPixelG = 0;
int nPixelB = 0;
if (colorFilterType == ColorFilterTypes.Red)
{
nPixelR = c.R;
nPixelG = c.G - 255;
nPixelB = c.B - 255;
}
else if (colorFilterType == ColorFilterTypes.Green)
{
nPixelR = c.R - 255;
nPixelG = c.G;
nPixelB = c.B - 255;
}
else if (colorFilterType == ColorFilterTypes.Blue)
{
nPixelR = c.R - 255;
nPixelG = c.G - 255;
nPixelB = c.B;
} nPixelR = Math.Max(nPixelR, 0);
nPixelR = Math.Min(255, nPixelR); nPixelG = Math.Max(nPixelG, 0);
nPixelG = Math.Min(255, nPixelG); nPixelB = Math.Max(nPixelB, 0);
nPixelB = Math.Min(255, nPixelB); bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR, (byte)nPixelG, (byte)nPixelB));
}
}
_currentBitmap = (Bitmap)bmap.Clone();
}
public static void Sharpen(Bitmap b, double k, short gem)
{
// Avoid divide by zero errors
Bitmap bSrc = (Bitmap)b.Clone(); // GDI+ still lies to us - the return format is BGR, NOT RGB.
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
BitmapData bmSrc = bSrc.LockBits(new Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int stride = bmData.Stride;
int stride2 = stride * 2;
System.IntPtr Scan0 = bmData.Scan0;
System.IntPtr SrcScan0 = bmSrc.Scan0; unsafe
{
byte * p = (byte *)(void *)Scan0;
byte * pSrc = (byte *)(void *)SrcScan0; int nOffset = stride - b.Width * 3;
int nWidth = b.Width - 2;
int nHeight = b.Height - 2; int nPixel;
double BASE = 0.0039; for(int y=0;y < nHeight;++y)
{
for(int x=0; x < nWidth; ++x )
{
int r;
r = ( pSrc[2] + pSrc[5] + pSrc[8] +
pSrc[2 + stride] + + pSrc[8 + stride] +
pSrc[2 + stride2] + pSrc[5 + stride2] + pSrc[8 + stride2] ) / 8;
nPixel = pSrc[5 + stride] - r;
if(Math.Abs(nPixel) > gem)
{
nPixel = (int) ( nPixel * k);
if(nPixel < 0)
nPixel = (int) ((nPixel * BASE + 1) * pSrc[5 + stride]);
else
nPixel = (int) (nPixel + pSrc[5 + stride]);
}
else
nPixel = (pSrc[5 + stride] + r) / 2; if (nPixel < 0) nPixel = 0;
if (nPixel > 255) nPixel = 255; p[5 + stride]= (byte)nPixel; int g;
g = ( pSrc[1] + pSrc[4] + pSrc[7] +
pSrc[1 + stride] + pSrc[7 + stride] +
pSrc[1 + stride2] + pSrc[4 + stride2] + pSrc[7 + stride2] ) / 8;
nPixel = pSrc[4 + stride] - g;
if(Math.Abs(nPixel) > gem)
{
nPixel = (int) (nPixel * k);
if(nPixel < 0)
nPixel = (int) ((nPixel * BASE + 1) * pSrc[4 + stride]);
else
nPixel = (int) (nPixel + pSrc[4 + stride]);
}
else
nPixel = (pSrc[4 + stride] + g) / 2; if (nPixel < 0) nPixel = 0;
if (nPixel > 255) nPixel = 255;
p[4 + stride] = (byte)nPixel; int b1;
b1 = ( pSrc[0] + pSrc[3] + pSrc[6] +
pSrc[0 + stride] + pSrc[6 + stride] +
pSrc[0 + stride2] + pSrc[3 + stride2] + pSrc[6 + stride2]) / 8;
nPixel = pSrc[3 + stride] - b1;
if(Math.Abs(nPixel) > gem)
{
nPixel = (int) (nPixel * k);
if(nPixel < 0)
nPixel = (int)((nPixel * BASE + 1) * pSrc[3 + stride]);
else
nPixel = (int) (nPixel + pSrc[3 + stride]);
}
else
nPixel = (pSrc[3 + stride] + b1) / 2; if (nPixel < 0) nPixel = 0;
if (nPixel > 255) nPixel = 255; p[3 + stride] = (byte)nPixel; p += 3;
pSrc += 3;
} p += nOffset;
pSrc += nOffset;
}
} b.UnlockBits(bmData);
bSrc.UnlockBits(bmSrc); bSrc.Dispose();
}