Closed Norc89 closed 2 years ago
It could be done using System.Drawing.Graphics
class. See the example:
private static Bitmap ScaleImage(Bitmap image, int targetWidth, int targetHeight)
{
var output = new Bitmap(targetWidth, targetHeight, PixelFormat.Format24bppRgb);
using (var g = Graphics.FromImage(output))
{
g.InterpolationMode = InterpolationMode.High;
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.AntiAlias;
var scale = Math.Min(targetWidth / (double)image.Width, targetHeight / (double)image.Height);
var scaleWidth = (int)(image.Width * scale);
var scaleHeight = (int)(image.Height * scale);
g.DrawImage(image, (targetWidth - scaleWidth) / 2, (targetHeight - scaleHeight) / 2, scaleWidth, scaleHeight);
}
return output;
}
Hi, I'm merging images and videos into one big video. The problem which i have is that if not all content is in the same ratio then content is stretched. I would like to have back borders on side. If is this possible how to set this ?