答案 0 :(得分:1)
我无法使用评论,很抱歉,如果我误解了这个问题。
您是否尝试将以下css应用于您的图片:
rateType
例如: https://jsfiddle.net/ba3sbow6/1/
我相信你只需要以编程方式更改图像的src?
答案 1 :(得分:1)
如果你想在代码中这样做,你需要相当多的东西。首先上传图像,在检查旋转时调整其大小。然后应用填充,然后保存或显示结果。
public void WriteImage(string path, int width, int height)
{
Bitmap bmp = new Bitmap(path);
float ratio = bmp.Width / bmp.Height;
SizeF newsize = new SizeF(width, height * ratio);
Bitmap newimage = new Bitmap((int)newsize.Width, (int)newsize.Height);
using (var graphics = Graphics.FromImage(newimage))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.DrawImage(bmp, 0, 0, width, height);
}
}