Example #1
0
        //[DllImport("gdi32.dll")]
        //static extern uint SetPixel(IntPtr hdc, int X, int Y, uint crColor);
        //[DllImport("gdi32.dll")]
        //static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
        //public static bool Conv3x3(IntPtr hDC, int nHeight, int nWidth, ConvMatrix m) {
        //  // Avoid divide by zero errors
        //  if (0 == m.Factor) return false;
        //  unsafe {
        //    int nPixel;
        //    byte[] color;
        //    for (int y = 0; y < nHeight; ++y) {
        //      for (int x = 0; x < nWidth; ++x) {
        //        color = GetPixel(hDC, x, y);
        //        nPixel = ((((pSrc[2] * m.TopLeft) + (pSrc[5] * m.TopMid) + (pSrc[8] * m.TopRight) +
        //          (pSrc[2 + stride] * m.MidLeft) + (pSrc[5 + stride] * m.Pixel) + (pSrc[8 + stride] * m.MidRight) +
        //          (pSrc[2 + stride2] * m.BottomLeft) + (pSrc[5 + stride2] * m.BottomMid) + (pSrc[8 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
        //        if (nPixel < 0) nPixel = 0;
        //        if (nPixel > 255) nPixel = 255;
        //        p[5 + stride] = (byte)nPixel;
        //        nPixel = ((((pSrc[1] * m.TopLeft) + (pSrc[4] * m.TopMid) + (pSrc[7] * m.TopRight) +
        //          (pSrc[1 + stride] * m.MidLeft) + (pSrc[4 + stride] * m.Pixel) + (pSrc[7 + stride] * m.MidRight) +
        //          (pSrc[1 + stride2] * m.BottomLeft) + (pSrc[4 + stride2] * m.BottomMid) + (pSrc[7 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
        //        if (nPixel < 0) nPixel = 0;
        //        if (nPixel > 255) nPixel = 255;
        //        p[4 + stride] = (byte)nPixel;
        //        nPixel = ((((pSrc[0] * m.TopLeft) + (pSrc[3] * m.TopMid) + (pSrc[6] * m.TopRight) +
        //          (pSrc[0 + stride] * m.MidLeft) + (pSrc[3 + stride] * m.Pixel) + (pSrc[6 + stride] * m.MidRight) +
        //          (pSrc[0 + stride2] * m.BottomLeft) + (pSrc[3 + stride2] * m.BottomMid) + (pSrc[6 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
        //        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);
        //  return true;
        //}
        public static bool Smooth(Bitmap b, int nWeight /* default to 1 */)
        {
            ConvMatrix m = new ConvMatrix();
            m.SetAll(1);
            m.Pixel = nWeight;
            m.Factor = nWeight + 8;

            return  BitmapFilter.Conv3x3(b, m);
        }
Example #2
0
        public static bool Sharpen(Bitmap b, int nWeight /* default to 11*/ )
        {
            ConvMatrix m = new ConvMatrix();
            m.SetAll(0);
            m.Pixel = nWeight;
            m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = -2;
            m.Factor = nWeight - 8;

            return  BitmapFilter.Conv3x3(b, m);
        }
Example #3
0
        public static bool GaussianBlur(Bitmap b, int nWeight /* default to 4*/)
        {
            ConvMatrix m = new ConvMatrix();
            m.SetAll(1);
            m.Pixel = nWeight;
            m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 2;
            m.Factor = nWeight + 12;

            return  BitmapFilter.Conv3x3(b, m);
        }
Example #4
0
        public static bool MeanRemoval(Bitmap b, int nWeight /* default to 9*/ )
        {
            ConvMatrix m = new ConvMatrix();
            m.SetAll(-1);
            m.Pixel = nWeight;
            m.Factor = nWeight - 8;

            return BitmapFilter.Conv3x3(b, m);
        }
Example #5
0
        public static bool EmbossLaplacian(Bitmap b)
        {
            ConvMatrix m = new ConvMatrix();
            m.SetAll(-1);
            m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 0;
            m.Pixel = 4;
            m.Offset = 127;

            return  BitmapFilter.Conv3x3(b, m);
        }