Image Filter Art---oilpaint oil painting filter

Source: Internet
Author: User
Tags image filter

oilpaint oil Painting filterImage painting effect is actually the edge of the image to create a hazy, atomized effect, at the same time, will be a certain edge blur, so that the image as a whole to see the pixels and pixels like a fog randomly presented. The algorithm process is as follows: Assume that the current pixel isP (x, y), his random position wasPd (Dx,dy), then the algorithm formula is as follows:

whereK (v) is a positive number of random numberswith a maximum value of less than v , andv is the atomization threshold,the greater thev value, The more obvious the atomization degree, conversely, the smaller the atomization degree,thev=0 , the image has no change effect.

The core code is as follows:

<summary>

Mosaic filter.

</summary>

<param name= "src" >source image.</param>

<param name= "BlockSize" >the size of Mosaic effect.</param>

<returns>resullt image.</returns>

Public Bitmap oilpaintfilter (Bitmap SRC, int. intensity)

{

Bitmap Srcbitmap = new Bitmap (SRC);

int w = srcbitmap.width;

int h = srcbitmap.height;

System.Drawing.Imaging.BitmapData srcdata = srcbitmap.lockbits (new Rectangle (0, 0, W, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

IntPtr ptr = srcdata.scan0;

int bytes = h * srcdata.stride;

byte[] srcvalues = new Byte[bytes];

System.Runtime.InteropServices.Marshal.Copy (PTR, srcvalues, 0, bytes);

Byte[] Tempvalues = (byte[]) srcvalues.clone ();

int stride = Srcdata.stride;

Random ran = new random ();

int k = 0;

int dx = 0;

int dy = 0;

for (int j = 0; J < H; j + +)

{

for (int i = 0; i < W; i++)

{

K = ran. Next (intensity);

DX = (i + k) >= W? W-1: (i + K);

DY = (j + k) >= h? H-1: (j + k);

Tempvalues[i * 4 + J * W * 4] = (byte) srcvalues[dx * 4 + dy * w * 4];

Tempvalues[i * 4 + 1 + J * W * 4] = (byte) SRCVALUES[DX * 4 + 1 + dy * w * 4];

Tempvalues[i * 4 + 2 + J * W * 4] = (byte) SRCVALUES[DX * 4 + 2 + dy * w * 4];

}

}

Srcvalues = (byte[]) tempvalues.clone ();

System.Runtime.InteropServices.Marshal.Copy (srcvalues, 0, ptr, bytes);

Srcbitmap.unlockbits (Srcdata);

return srcbitmap;

}

Image oil Painting filter effect is as follows:

Original

Oilpaint Filter Effect

Finally, put a complete C # version of the program demo download Link: http://www.zealpixel.com/forum.php?mod=viewthread&tid=52&extra=page%3D1

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

Image Filter Art---oilpaint oil painting 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.