Image Filter Art---spherical (spherize) filter

Source: Internet
Author: User
Tags image filter

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

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.