欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现给图片加边框的方法

程序员文章站 2022-06-14 11:56:50
1 Bitmap bit= new Bitmap(@"" + Path);//给图片加边框 2 //Bitmap bit = new Bitmap(Screen.AllScreens[0].Bounds.Size.Width, Screen.AllScreens[0].Bounds.Size.Hei... ......

 

 1  Bitmap bit= new Bitmap(@"" + Path);//给图片加边框
 2  //Bitmap bit = new Bitmap(Screen.AllScreens[0].Bounds.Size.Width, Screen.AllScreens[0].Bounds.Size.Height);//给当前桌面图加边框
 3  float w = (float)(bit.Width * 0.2);//边框的宽度,可取任意值
 4   using (Graphics g = Graphics.FromImage(bit))
 5   {
 6       // g.CopyFromScreen(0, 0, 0, 0, Screen.AllScreens[0].Bounds.Size);//抓取背景图
 7         using (Pen pen = new Pen(Color.White, w))
 8        { 
 9        //g.DrawRectangle(pen, new Rectangle(0, 0, Screen.AllScreens[0].Bounds.Size.Width, Screen.AllScreens[0].Bounds.Size.Height));//给当前桌面画白框
10         //g.DrawRectangle(pen, new Rectangle(0, 0, Math.Abs(bit.Width), Math.Abs(bit.Height)));//加边框
11          g.DrawEllipse(pen, new Rectangle(0, 0, Math.Abs(bit.Width), Math.Abs(bit.Height)));//加椭圆边框
12           g.Dispose();
13         // pic.BackgroundImage = bit;
14        } 
15    }