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