/// <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 );
}