Method of adding photo frame to picture by C
- 2021-09-11 20:56:45
- OfStack
In this paper, an example is given to describe the method of adding photo frame to pictures by C #. Share it for your reference, as follows:
// Border
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)
{
}
// Add ellipse
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)
{
}
For more readers interested in C # related content, please check out the topics on this site: "C # Introduction to Object-Oriented Programming", "C # Common Control Usage Tutorial" and "C # Data Structure and Algorithm Tutorial"
I hope this article is helpful to everyone's C # programming.