I have an image of a and b width and height.
I need to create a new image of x and y height, keeping the original contents of the image central and adding white pixels to fill the part of the image that has been added to make it x and y width.
So almost like a white border all the way around
This is as close as I get at the moment. But i can't get my head around how to get the calculated border size and apply it.
// download the file from the url as a stream
using System.Net.WebClient webClient = new System.Net.WebClient();
using Stream stream = webClient.OpenRead(urlToImage);
// create a bitmap image from the stream
Bitmap bitmap = new Bitmap(stream);
// work out how much the image needs to get bigger by
int increaseWidthBy = finalWidth - bitmap.Width;
int increaseHeightBy = finalHeight - bitmap.Height;
Graphics gr = Graphics.FromImage(bitmap);
gr.DrawLine(new Pen(Brushes.White, 20), new Point(0, 0), new Point(0, 40));
gr.DrawLine(new Pen(Brushes.White, 20), new Point(0, 0), new Point(40, 0));
gr.DrawLine(new Pen(Brushes.White, 20), new Point(0, 40), new Point(40, 40));
gr.DrawLine(new Pen(Brushes.White, 20), new Point(40, 0), new Point(40, 40));
gr.DrawImage(bitmap, 0, 0, finalWidth, finalHeight);
Bitmap newimage = new Bitmap(finalWidth, finalHeight);
using MemoryStream memory = new MemoryStream();
using FileStream fs = new FileStream(fileName, FileMode.Create);
newimage.Save(memory, ImageFormat.Jpeg);
byte[] bytes = memory.ToArray();
fs.Write(bytes, 0, bytes.Length);
Any help would be greatly appreciated.