Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8521643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:53:06+00:00 2026-06-11T06:53:06+00:00

The Plan I need to reduce image sizes, while keeping some quality. However, I

  • 0

The Plan

I need to reduce image sizes, while keeping some quality.
However, I am accepting GIF, JPEG, JPG and PNG.


The Current Situation

The uploading of the image is compleetly functional, and I have been able to scale its width and/or height with sucess.

I found an awesome post here on Stackoverflow, that gave me a very good sample of code:

Image myImage = //... load the image somehow 

// Save the image with a quality of 50%
SaveJpeg (destImagePath, myImage, 50);
//add this!
using System.Drawing.Imaging;

                      /// <summary> 
    /// Saves an image as a jpeg image, with the given quality 
    /// </summary> 
    /// <param name="path">Path to which the image would be saved.</param> 
    // <param name="quality">An integer from 0 to 100, with 100 being the 
    /// highest quality</param> 
    public static void SaveJpeg (string path, Image img, int quality) 
    { 
        if (quality<0  ||  quality>100) 
            throw new ArgumentOutOfRangeException("quality must be between 0 and 100."); 


        // Encoder parameter for image quality 
        EncoderParameter qualityParam = 
            new EncoderParameter (Encoder.Quality, quality); 
        // Jpeg image codec 
        ImageCodecInfo   jpegCodec = GetEncoderInfo("image/jpeg"); 

        EncoderParameters encoderParams = new EncoderParameters(1); 
        encoderParams.Param[0] = qualityParam; 

        img.Save (path, jpegCodec, encoderParams); 
    } 

    /// <summary> 
    /// Returns the image codec with the given mime type 
    /// </summary> 
    private static ImageCodecInfo GetEncoderInfo(string mimeType) 
    { 
        // Get image codecs for all image formats 
        ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); 

        // Find the correct image codec 
        for(int i=0; i<codecs.Length; i++) 
            if(codecs[i].MimeType == mimeType) 
                return codecs[i]; 
        return null; 
    } 

However, this code seems to work with JPEG images only.


The Questions

  1. Is JPEG format lighter than PNG or GIF? And if so, should I convert and save all images in JPEG?
    • In this case, the sample code should work just fine right?
    • If not, given the sample code, what can we do use other formats?
  2. What tools can we use in C# to reduce the image weight? (besides reducing the dimensions)
  3. What is the recommended “quality loss” for an image, in order to preserve a reasonable status of readability, color, sharpness and definition?
  4. Is image processing “heavy” on the server?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:53:07+00:00Added an answer on June 11, 2026 at 6:53 am

    First of all, JPEG uses a “lossy” compression algorithm, which is why you can tune the quality. Lower quality will result better compression at the cost of higher data loss. Also realize that the JPEG format is designed for photograph-like images, and applying JPEG to other types of images can be disappointing (google “jpeg artifacts”).

    PNG and GIF are lossless, so they can’t support a quality parameter. This isn’t to say that you can’t get better compression out of them – there’s a variety of tools to reduce the size of your PNG’s (pngcrush, punypng, etc), but these tools (mostly) work in a fundamentally different way than JPEG compressors do. One thing to note is that GIF supports a smaller palette than PNG – only up to 256 colors.

    So to answer your questions in order:

    1. Can’t really compare, since compression in JPEG comes with a tradeoff while compression in PNG and GIF doesn’t, and how tolerable the tradeoff is depends on the type of image. That is, JPEG will often give better compression, but if the image isn’t a photograph the result will be noticeably worse.

    2. Your code for JPEG is fine. Google for C#-compatible tools for PNG.

    3. You’ll need to experiment with the types of images you expect.

    4. Yes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got some problem and need help .. my plan : 1. get ip
I need an formula for determining a debt payoff plan where the following are
Need an async I/O Processing Plan to use async I/O through aio* calls on
I plan on building a simple, yet high usage webapp and need to settle
I need to add some collection routes for a nested resource. I have a
I need to add a soap header to my web service. I plan to
I need to complete the plan of a ask-a-question site for my uni. in
I need to extract a set of characters in of a string. I plan
I need to import different feeds at different times, and my plan is to
I plan on running my application using Heroku, Sunspot and WebSolr and need an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.