The Swirl filterswirl filter is the effect of implementing a distorted rotation of the image around the center point (cenx,ceny), as follows: Original The code is as follows: // /// Swirl Filter /// Source image. The X position of swirl. The Y position of swirl. The degree of swirl,0-360. The result image. Private Bitmap swirlfilterprocess (Bitmap srcbitmap, int cenx, int ceny, int swildegree) { Bitmap a = new Bitmap (SRCBITMAP); int w = a.width; int h = a.height; int radius = 0; Swildegree = Math.max (0, Math.min (swildegree)); Double k = swildegree/3600.0; Bitmap DST = new Bitmap (w, h); System.Drawing.Imaging.BitmapData srcdata = a.lockbits (new Rectangle (0, 0, W, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Imaging.BitmapData Dstdata = DST. LockBits (New Rectangle (0, 0, W, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, SYSTEM.DRAWING.IMAGING.PIXELFORMAT.FORMAT32BPPARGB); Unsafe { byte* pIn = (byte*) srcData.Scan0.ToPointer (); byte* POut = (byte*) dstData.Scan0.ToPointer (); byte* p = null; int stride = srcdata.stride-w * 4; int OffsetX = 0, OffsetY = 0; int newx = 0, newy = 0; Double radian = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < W; + +) { OffsetX = X-cenx; OffsetY = Y-ceny; Radian = Math.atan2 (OffsetY, OffsetX); RADIUS = (int) (MATH.SQRT (OffsetX * offsetX + OffsetY * offsetY)); NEWX = (int) (RADIUS * Math.Cos (radian + k * radius)) + Cenx; Newy = (int) (RADIUS * Math.sin (radian + k * radius)) + ceny; Newx = Math.min (w-1, Math.max (0, newx)); Newy = Math.min (h-1, Math.max (0, newy)); p = pIn + newy * srcdata.stride + newx * 4; Pout[0] = (byte) p[0]; POUT[1] = (byte) p[1]; POUT[2] = (byte) p[2]; POUT[3] = (byte) 255; POut + = 4; } POut + = Stride; } A.unlockbits (Srcdata); Dst. Unlockbits (Dstdata); } return DST;
} Finally put a complete C # program demo:http://www.zealpixel.com/thread-58-1-1.html, in addition, recommend a URL www.zealpixel.com, there are a lot of good image processing open source code! |