Spherical (spherize) filter Spherical filter is a spherical effect of the image by polar coordinate transformation. The code is as follows: // /// Pinch Filter Source image. The X position of sun. The Y position of sun. The result image. Private Bitmap spherizefilterprocess (Bitmap srcbitmap, int cenx, int ceny) { Bitmap a = new Bitmap (SRCBITMAP); int w = a.width; int h = a.height; int radius = 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 swidth = Srcdata.stride; int stride = swidth-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) ((OffsetX * OffsetX + OffsetY * OffsetY)/Math.max (Cenx, ceny)); NEWX = (int) (RADIUS * Math.Cos (radian)) + Cenx; Newy = (int) (RADIUS * Math.sin (radian)) + 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;} As follows: Original (x=240,y=240) Finally put a complete C # board program DEMO:HTTP://WWW.ZEALPIXEL.COM/FORUM.PHP?MOD=VIEWTHREAD&TID=56&EXTRA=PAGE%3D1 |
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Image Filter Art---spherical (spherize) filter