码迷,mamicode.com
首页 > 其他好文 > 详细

批量生成不同尺寸的图片

时间:2016-09-21 12:55:29      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

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; }
}

批量生成不同尺寸的图片

标签:

原文地址:http://www.cnblogs.com/wuwei928/p/5892078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!