小日本的图片处理C#类

    本来想写一个将图片处理成磨砂玻璃的函数,从网上找到一个C#的类,小日本的代码,功能较多,没有注释。处理出来的效果还可以,但不是我想要的
ImageUtils.cs

用这个类写的“磨砂玻璃”效果如下:

代码:
        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, 
00, rect, GraphicsUnit.Pixel);
            g.Dispose();

            ImgUtils.GaussianBlur(
ref tmp, blurZone);

            Bitmap tmp2 
= tmp.Clone() as Bitmap;
            g 
= Graphics.FromImage(tmp2);
            g.Clear(Color.FromArgb(
244244244));
            ImgUtils.JAlphaBlend(g, tmp, (
float)alphaPercent / 100f, 00);
            g.Dispose();

            tmp.Dispose();

            g 
= Graphics.FromImage(bmp);
            g.DrawImageUnscaled(tmp2, rect.Left, rect.Top);
            g.Dispose();

            tmp2.Dispose();

            
return true;
        }

        
private void button1_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(8850219550), 503))
            {
                g.DrawImageUnscaled(bmp, 
55);
                Clipboard.SetImage(bmp);
            }

            g.Dispose();
            bmp.Dispose();
        }


posted @ 2007-11-08 16:27  元宝  阅读(1948)  评论(5编辑  收藏  举报
我最爱的地质软件?!……