Click here to Skip to main content
15,885,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi all i am working on webapi i need to optimize the images from folder

here i Had Uploaded images into one folder before

uploading in to the destination folder i need to decrease the image size in KB of total images

here i am optimizing a single image in to 3 different sizes' (large, thumbnail,medium)' but image sizes are increased and saved in one folder now i need to optimize those images could u plz help me how could i do that. actually i am new to webapi. any body could have any idea please help me but one thing i need to do this manually thankyou in advance
Posted

If you want to reduce the uploaded image size only , and retain its quality this link will be helpful

how to resize image without losing image quality or how to reduce image file size without losing quality using asp.net
 
Share this answer
 
Comments
shakil4u 26-Sep-12 6:44am    
yes but it is for only asp.net i need to be work in webapi thankyou for time spent for me if ane other help ploease help me
shakil4u 26-Sep-12 12:06pm    
thank for your answer i got it
as of above question no problem i think it is increasing with quality option you just have to do simple just decrease the quality make upload image and check it once


C#
public static void Resize(string original, string output, int width, int height)
        {
            using (var image = Image.FromFile(original))
            using (var thumbnail = new Bitmap(width, height))
            using (var graphics = Graphics.FromImage(thumbnail))
            {
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                graphics.CompositingQuality = CompositingQuality.HighQuality;

                graphics.DrawImage(image, 0, 0, width, height);

                ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders();
                EncoderParameters encoderParameters;
                encoderParameters = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 80L);
                thumbnail.Save(output, info[1], encoderParameters);
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900