批量生成不同尺寸的图片

Posted Beier928

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量生成不同尺寸的图片相关的知识,希望对你有一定的参考价值。

static void Main(string[] args)
{
var image = Image.FromFile("C:\\picture\\600.png");
var pictureSize = new List<Picture>();
pictureSize.Add(new Picture { Width = 256, Height = 256 });
pictureSize.Add(new Picture { Width = 48, Height = 48 });
pictureSize.Add(new Picture { Width = 24, Height = 24 });
pictureSize.Add(new Picture { Width = 16, Height = 16 });
//pictureSize.Add(new Picture { Width = 388, Height = 388 });
foreach (var picture in pictureSize)
{
Bitmap map = new Bitmap(picture.Width, picture.Height);
Graphics graphics = Graphics.FromImage(map);
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, picture.Width, picture.Height);
graphics.DrawImage(image, imageRectangle);
map.Save("C:\\picture\\result\\"+picture.Width + "x" + picture.Height+".png", ImageFormat.Png);
graphics.Dispose();
map.Dispose();
}
image.Dispose();
}

public class Picture
{
public int Height { get; set; }
public int Width { get; set; }
}

以上是关于批量生成不同尺寸的图片的主要内容,如果未能解决你的问题,请参考以下文章

使用python批量生成word文档

批量生成测试非重复命名的图片数据

基于.NetCore开发博客项目 StarBlog - (15) 生成随机尺寸图片

python处理图片数据?

如何批量调整Word中图片大小

Python 批量处理图片,生成gif动图