C#实现图片加相框的方法

时间:2021-09-19 11:34:48

本文实例讲述了C#实现图片加相框的方法。分享给大家供大家参考,具体如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//加边框
try
{
  Bitmap Backbmp = new Bitmap(@"" + Path);
  float w = (float)(Backbmp.Width * 0.2);
  using (Graphics g = Graphics.FromImage(Backbmp))
  {
    using (Brush brush = new SolidBrush(Color.FromArgb(0, 156, 255)))
    {
      using (Pen pen = new Pen(brush, w))
      {
        pen.DashStyle = DashStyle.Custom;
        g.DrawRectangle(pen, new Rectangle(0, 0, Math.Abs(Backbmp.Width), Math.Abs(Backbmp.Height)));
        g.Dispose();
        pic.BackgroundImage = Backbmp;
      }
    }
  }
}
catch (Exception)
{
}
//加椭圆
try
{
  Bitmap Backbmp = new Bitmap(@"" + Path);
  float w = (float)(Backbmp.Width * 0.2);
  using (Graphics g = Graphics.FromImage(Backbmp))
  {
    using (Brush brush = new SolidBrush(Color.FromArgb(0, 156, 255)))
    {
      using (Pen pen = new Pen(brush, w))
      {
        pen.DashStyle = DashStyle.Custom;
        g.DrawEllipse(pen, new Rectangle(0, 0, Math.Abs(Backbmp.Width), Math.Abs(Backbmp.Height)));
        g.Dispose();
        pic.BackgroundImage = Backbmp;
      }
    }
  }
}
catch (Exception)
{
}

希望本文所述对大家C#程序设计有所帮助。