Draw Border on Bitmap - CSharp System.Drawing

CSharp examples for System.Drawing:Image Operation

Description

Draw Border on Bitmap

Demo Code


using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using System;//from  ww w. ja va 2  s .  c om

public class Main{
        public static Bitmap Border(Bitmap orig, Color color, int penwidth = 1) {
         Bitmap b = new Bitmap(orig.Width, orig.Height);
         Graphics g = Graphics.FromImage(b);
         g.DrawImage(orig, 0, 0);
         g.DrawRectangle(new Pen(color, penwidth),
            penwidth - 1, penwidth - 1,
            orig.Width - penwidth, orig.Height - penwidth);
         return b;
      }
}

Related Tutorials