I have got a System.Drawing.Bitmap
in my code.
The width is fix, the height varies.
What I want to do, is to add a white border around the bitmap, with about 20 pixel, to all 4 edges.
How would this work?
You could draw a rectangle behind the bitmap. The width of the rectangle would be (Bitmap.Width + BorderWidth * 2), and the position would be (Bitmap.Position - new Point(BorderWidth, BorderWidth)). Or at least that's the way I'd go about it.
EDIT: Here is some actual source code explaining how to implement it (if you were to have a dedicated method to draw an image):
private void DrawBitmapWithBorder(Bitmap bmp, Point pos, Graphics g) {
const int borderSize = 20;
using (Brush border = new SolidBrush(Color.White /* Change it to whichever color you want. */)) {
g.FillRectangle(border, pos.X - borderSize, pos.Y - borderSize,
bmp.Width + borderSize, bmp.Height + borderSize);
}
g.DrawImage(bmp, pos);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With