Image Mosaic Effect

Source: Internet
Author: User

/// <Summary>
/// Mosaic Effect
/// Principle: Determine the random position of the image and determine the size of the mosaic block, and then overwrite the random point of the mosaic block image.
/// </Summary>
/// <Param name = "m_iimage"> </param>
/// <Param name = "Val"> split into cell blocks with Val * val pixels </param>
Public Image masaike (image m_preimage, int Val)
{
Bitmap mybitmap = new Bitmap (m_preimage );
If (mybitmap. Equals (null ))
{
Return NULL;
}
Int iwidth = mybitmap. width;
Int iheight = mybitmap. height;
Int stdr, stdg, stdb;
Stdr = 0;
Stdg = 0;
Stdb = 0;
Bitmapdata srcdata = mybitmap. lockbits (New rectangle (0, 0, iwidth, iheight ),
Imagelockmode. readwrite, pixelformat. format24bpprgb );
Unsafe
{
Byte * point = (byte *) srcdata. scan0.topointer ();
For (INT I = 0; I <iheight; I ++)
{
For (Int J = 0; j <iwidth; j ++)
{
If (I % val = 0)
{
If (J % val = 0)
{
Stdr = point [2];
Stdg = point [1];
Stdb = point [0];
}
Else
{
Point [0] = (byte) stdb;
Point [1] = (byte) stdg;
Point [2] = (byte) stdr;
}
}
Else
{
// Copy the previous row
Byte * ptemp = point-srcdata. stride;
Point [0] = (byte) ptemp [0];
Point [1] = (byte) ptemp [1];
Point [2] = (byte) ptemp [2];
}
Point + = 3;
}
Point + = srcdata. stride-iwidth * 3;
}
Mybitmap. unlockbits (srcdata );
}
Return mybitmap;
}

Private void button#click (Object sender, eventargs E)
{
This. picturebox2.image = masaike (this. picturebox1.image, 8 );
}

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.