C#实现给图片加边框的方法
程序员文章站
2023-11-11 22:57:58
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 }
上一篇: 网站推广软文写作时候应该注意哪些方面