C#改变图片大小

时间:2023-01-10 23:32:00

今天一女同事要做一个改变图片大小的功能,然后我就手写了几行代码,以后可能用得上

            byte[] buffer = new byte[1];

            //Byte转为Image对象
MemoryStream ms = new MemoryStream(buffer);
Image image = System.Drawing.Image.FromStream(ms); //设置画布,绘画新图片
Bitmap b = new Bitmap(200, 200);
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//绘制图像
g.DrawImage(image, 0, 0, 200, 200);
g.Dispose();
//保存图片
b.Save("aaaaaaaaa");