Image Filter Art---swirl filter

Source: Internet
Author: User
Tags image filter

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!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Image Filter Art---swirl filter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.