不知道C#有没有前辈做过锐化。
flickr的锐化效果非常棒的说。

解决方案 »

  1.   

    不知道这个是不是,转一段代码
    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();
            }
      

  2.   

    以前写的一个为冲洗机而设定的锐化:
    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();
    }