Image Filter art-sphere filter, sphere Spherize
Spherize Filter A Spherical filter is used to implement the spherical effect of an image through 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 =. 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 { For (int x = 0; x <w; x ++) { 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: Source image (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 Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.