var img = System.Drawing.Image.FromStream(ms);
int width = img.Width;
int height = img.Height;
var x = img.HorizontalResolution;
var y = img.VerticalResolution;
var tempHeight = height * 300 / y;
var tempWidth = width * 300 / y;
Bitmap bmpTemp = new Bitmap((int)tempWidth, (int)tempHeight);
Graphics g = Graphics.FromImage(bmpTemp);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.Clear(System.Drawing.Color.White);
g.DrawImage(img, new RectangleF(0, 0, tempWidth, tempHeight), new RectangleF(0, 0, width, height), GraphicsUnit.Pixel);
g.Save();
bmpTemp.Save(target, ImageFormat.Png);
g.Dispose();
img.Dispose();
bmpTemp.Dispose();
感谢每一位阅读此篇文章的人,希望可以帮到你。