Image manipulation in C #

I need to resize images on a website that I create for my company. Images must be of a very specific size, and if the proportions are not correct, I must be able to overlay the image on the border to make it β€œfit”. I am not sure what is the best way to approach this problem. My knee-jerk reflex was just to add Rectangles to the image on the go, as I needed, but I can't find a way to make the composite image this way. Should I just create a suitable empty rectangle and overlay my image on it? What libraries or features should I look at the most?

Resizing perfectly and working economically is not a problem. Adding this add-on is the only problem.

+4
source share
3 answers

Create a new Bitmap desired size, fill it with the color of the gasket and select the original image in the center:

 Bitmap newImage = new Bitmap(width, height); using(Graphics graphics = Graphics.FromImage(newImage)) { graphics.Clear(paddingColor); int x = (newImage.Width - originalImage.Width) / 2; int y = (newImage.Height - originalImage.Height) / 2; graphics.DrawImage(originalImage, x, y); } 
+8
source
+1
source

The easiest way is to start with a bitmap with the dimensions that you need in the final image, and then use Graphics.Clear to draw the desired background color, and then use Graphics.DrawImage to copy the original image to your main bitmap, resize to as necessary during this step and to ensure the best quality for IntercolationMode for HighQualityBicubic.

+1
source

All Articles