C# 文件夹扫描图像和图像大小调整取决于图像宽度

C# 文件夹扫描图像和图像大小调整取决于图像宽度,c#,image,image-resizing,C#,Image,Image Resizing,可以借助C#调整图像大小吗?我有一个文件夹,里面有成千上万张照片。我需要做一个应用程序,将扫描该文件夹中的所有图像,并检查其大小参数,然后那些宽度低于300px的将按比例调整大小,使其宽度等于300px。可能吗?然后它会是什么样子。检查此线程。它包含调整图像大小的代码示例 要获取文件夹中所有文件的文件名,可以使用 var startPath = @"c:\temp"; var imageFileExtensions = new [] { ".jpg", ".gif", ".jpeg",

可以借助C#调整图像大小吗?我有一个文件夹,里面有成千上万张照片。我需要做一个应用程序,将扫描该文件夹中的所有图像,并检查其大小参数,然后那些宽度低于300px的将按比例调整大小,使其宽度等于300px。可能吗?然后它会是什么样子。

检查此线程。它包含调整图像大小的代码示例 要获取文件夹中所有文件的文件名,可以使用

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

检查这条线。它包含调整图像大小的代码示例 要获取文件夹中所有文件的文件名,可以使用

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

也许是这样的@Oldskool链接不再好了。可能是这样的吧@Oldskool链接不再好。请避免仅链接答案,至少提供流程摘要。请避免仅链接答案,至少提供流程摘要。