本文實例講述了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)
{
}