文件夹扫描图像和图像大小调整取决于图像宽度
本文关键字:图像 取决于 调整 扫描 文件夹 | 更新日期: 2023-09-27 17:50:28
是否有可能在c#的帮助下调整图像的大小?我有一个文件夹,里面有成千上万张照片。我需要做一个应用程序,扫描文件夹的所有图像,并检查它们的大小参数,然后那些宽度低于300px将被调整为宽度等于300px。这可能吗?然后是什么样子
检查这个线程。它包含调整图像大小的代码示例http://forums.asp.net/t/1038068.aspx要获取文件夹中所有文件的文件名,可以使用
var startPath = @"c:'temp";
var imageFileExtensions =
new [] { ".jpg", ".gif", ".jpeg", ".png", ".bmp" };
var pathsToImages =
from filePath in Directory.EnumerateFiles(
startPath,
"*.*",
SearchOption.AllDirectories)
where imageFileExtensions.Contains(Path.GetExtension(filePath))
select filePath;
可以使用
来调整图像的大小 public System.Drawing.Bitmap ResizeImage(System.Drawing.Image image, int width, int height)
{
//a holder for the result
Bitmap result = new Bitmap(width, height);
//use a graphics object to draw the resized image into the bitmap
using (Graphics graphics = Graphics.FromImage(result))
{
//set the resize quality modes to high quality
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//draw the image into the target bitmap
graphics.DrawImage(image, 0, 0, result.Width, result.Height);
}
//return the resulting bitmap
return result;
}