The Swirl FilterSwirl filter turns an image around the center point (cenX, cenY) as follows: Source image 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 (360, swilDegree )); Double k = swilDegree/3600.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 stride = srcData. Stride-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) (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: Success! |