How to resizing bulk images at once by using a good tool in Asp.net

Aypn CNN 446 Reputation points
2022-10-19T06:53:12.76+00:00

Please provide a solution for resizing multiple images at once.

As an example, I have a folder named "A" that contains 100 images with file sizes greater than 300KBs. I want to decrease all of the files' sizes such that they are all under 300KBs. File name and file extension should not be modified during conversion and same copied into Folder "B"; they should remain the same while maintaining acceptable image quality.

The solution can be implement into a Asp.net project or suitable one.

Thanks in advance.

Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-10-19T09:20:53.297+00:00

    Hi @Aypn CNN ,
    I think if you want to resize the image, you can simply use the constructor with the image to create an instance of the Bitmap class, you can refer to the code below:
    https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=dotnet-plat-ext-6.0

    If you use VB.NET, you can try Magick.NET. ImageMagick is a powerful image processing library that supports over 100 major file formats (excluding sub-formats).
    https://github.com/dlemstra/Magick.NET/

    private void ReduceImageSize(double scaleFactor, Stream sourcePath, string targetPath)  
            {  
                using (var image = System.Drawing.Image.FromStream(sourcePath))  
                {  
                    var newWidth = (int)(image.Width * scaleFactor);  
                    var newHeight = (int)(image.Height * scaleFactor);  
                    var thumbnailImg = new Bitmap(newWidth, newHeight);  
                    var thumbGraph = Graphics.FromImage(thumbnailImg);  
                    thumbGraph.CompositingQuality = CompositingQuality.HighQuality;  
                    thumbGraph.SmoothingMode = SmoothingMode.HighQuality;  
                    thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;  
                    var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);  
                    thumbGraph.DrawImage(image, imageRectangle);  
                    thumbnailImg.Save(targetPath, image.RawFormat);  
                }  
            }  
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.