I originally wanted to write a function to process images into frosted glass. I found a class C # on the Internet, with many features and no comments. The processing results are acceptable, but they are not what I want.
ImageUtils. cs
The effect of "frosted glass" written in this class is as follows:
Code: Public static bool FrostedGlass (ref Bitmap bmp, Rectangle rect,
Int alphaPercent, int blurZone)
{
If (bmp. PixelFormat! = PixelFormat. Format24bppRgb)
Return false;
Int w = bmp. Width;
Int h = bmp. Height;
Bitmap tmp = new Bitmap (rect. Width, rect. Height,
PixelFormat. Format24bppRgb );
Graphics g = Graphics. FromImage (tmp );
G. DrawImage (bmp, 0, 0, rect, GraphicsUnit. Pixel );
G. Dispose ();
ImgUtils. GaussianBlur (ref tmp, blurZone );
Bitmap tmp2 = tmp. Clone () as Bitmap;
G = Graphics. FromImage (tmp2 );
G. Clear (Color. FromArgb (244,244,244 ));
ImgUtils. JAlphaBlend (g, tmp, (float) alphaPercent/100f, 0, 0 );
G. Dispose ();
Tmp. Dispose ();
G = Graphics. FromImage (bmp );
G. DrawImageUnscaled (tmp2, rect. Left, rect. Top );
G. Dispose ();
Tmp2.Dispose ();
Return true;
}
Private void button#click (object sender, EventArgs e)
{
Bitmap bmp = new Bitmap (@ "C: home‑img2‑reika1.png ");
Graphics g = this. CreateGraphics ();
// G. DrawImageUnscaled (bmp, 5, 5 );
If (FrostedGlass (ref bmp, new Rectangle (88, 50,219,550), 50, 3 ))
{
G. DrawImageUnscaled (bmp, 5, 5 );
Clipboard. SetImage (bmp );
}
G. Dispose ();
Bmp. Dispose ();
}