Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Image quality

Image quality

Scheduled Pinned Locked Moved C#
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    How can I reduce image quality when I'm saving an image to reduce its size? Thanks

    N J 2 Replies Last reply
    0
    • M Mazdak

      How can I reduce image quality when I'm saving an image to reduce its size? Thanks

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      One simple way is to change the resolution using Bitmap.SetResolution() method to a less value.

      Regards:rose:

      M 1 Reply Last reply
      0
      • M Mazdak

        How can I reduce image quality when I'm saving an image to reduce its size? Thanks

        J Offline
        J Offline
        J Dunlap
        wrote on last edited by
        #3

        You can use the Quality encoder parameter, which works only with the JPEG encoder. Here's how to specify a quality level when saving an image:

        //Get all the image encoders and find the one for the JPEG format
        ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
        ImageCodecInfo codec = null;
        foreach(ImageCodecInfo c in codecs)
        {
        if(c.MimeType=="image/jpeg")
        {
        codec=c;
        break;
        }
        }

        //Create a list of encoder parameters with space for a single entry
        EncoderParameters encoderParams=new EncoderParams(1);
        //Create a parameter to pass to the codec, with the category "Quality" and
        //the desired quality value (where 100 is 100% quality)
        EncoderParameter encoderParam=new EncoderParameter(Encoder.Quality, 90L);
        //Add the parameter to the list of encoder parameters
        encoderParams.Param[0]=encoderParam;

        //Save the bitmap using the JPEG encoder and the parameter list
        bmp.Save(filename,codec,encoderParams);

        C# / DHTML / VG.net / MyXaml expert currently looking for work![^]

        M 1 Reply Last reply
        0
        • J J Dunlap

          You can use the Quality encoder parameter, which works only with the JPEG encoder. Here's how to specify a quality level when saving an image:

          //Get all the image encoders and find the one for the JPEG format
          ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
          ImageCodecInfo codec = null;
          foreach(ImageCodecInfo c in codecs)
          {
          if(c.MimeType=="image/jpeg")
          {
          codec=c;
          break;
          }
          }

          //Create a list of encoder parameters with space for a single entry
          EncoderParameters encoderParams=new EncoderParams(1);
          //Create a parameter to pass to the codec, with the category "Quality" and
          //the desired quality value (where 100 is 100% quality)
          EncoderParameter encoderParam=new EncoderParameter(Encoder.Quality, 90L);
          //Add the parameter to the list of encoder parameters
          encoderParams.Param[0]=encoderParam;

          //Save the bitmap using the JPEG encoder and the parameter list
          bmp.Save(filename,codec,encoderParams);

          C# / DHTML / VG.net / MyXaml expert currently looking for work![^]

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          Thanks for reply, but my files are in tif format.

          Mazy
          "One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji

          G 1 Reply Last reply
          0
          • N Nader Elshehabi

            One simple way is to change the resolution using Bitmap.SetResolution() method to a less value.

            Regards:rose:

            M Offline
            M Offline
            Mazdak
            wrote on last edited by
            #5

            Thanks for reply but it doesn't help. I want to reduce file size.

            Mazy
            "One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji

            1 Reply Last reply
            0
            • M Mazdak

              Thanks for reply, but my files are in tif format.

              Mazy
              "One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              Unless the TIFF file uses JPEG compression (which is possible, but kind of pointless), the compression is lossless. That means that you can not change the quality of the compression as the compression does not make any quality compromises. Unless you specifically need the TIFF format, you could try the PNG format instead. It is also lossless, but compresses a lot better. If you want lossy compression, use the JPEG format.

              --- Year happy = new Year(2007);

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups