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

  • SEARCH
  • Home
  • 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 8911071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:50:56+00:00 2026-06-15T03:50:56+00:00

Here’s the deal. I’m trying to use a function to compress an image from

  • 0

Here’s the deal. I’m trying to use a function to compress an image from my notebook camera while using a standard code to do that:

    public static byte[] EncodeImage(this Image image)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
            EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80);
            EncoderParameters encoderParams = new EncoderParameters(1);
            encoderParams.Param[0] = qualityParam;

            image.Save(ms, jpegCodec, encoderParams);
            return ms.ToArray();
        }
    }

After the compression is done, I save it to the database. Works good, providing me with a good amount of compression (500 000 bytes vs 32 000). Some time later, I need to show the image to the user in a winforms application.

using (MemoryStream ms = new MemoryStream(entity.Photo))
    fotoPictureBox.Image = Image.FromStream(ms);

Again, this displays a nice image. However, then I want the user to be able to download the image and save where he sees suitable. And this is when all the problems arise.

If I use this code:

fotoPictureBox.Image.Save(imageSaveFileDialog.FileName);

I receieve a typical generic GDI+ error.
If I try to save the image by using the code I’ve encoded it

     public static void SaveEncodedImage(this Image image, string targetPath)
    {
        ImageCodecInfo jpegCodec = Pomocne.GetEncoderInfo("image/jpeg");
        EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80);
        EncoderParameters encoderParams = new EncoderParameters(1);
        encoderParams.Param[0] = qualityParam;

        image.Save(targetPath, jpegCodec, encoderParams);
    }

I get this error (pointing to the line image.Save(targetPath, jpegCodec, encoderParams);):

An unhandled exception of type System.ArgumentException occurred in System.Drawing.dll
Additional information: Parameter is not valid.

Can please anyone help? It’s rather urgent, thank you.

To address some questions/answers you will probably start with – if I don’t compress the image with this code, I can save the image to the chosen path without any problems. So there’s clearly some problem with decoding or something like that. Don’t ask me if I have sufficient permissions, because I have.

  • 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-15T03:50:57+00:00Added an answer on June 15, 2026 at 3:50 am

    For some reason this code works great:

    File.WriteAllBytes(targetPath, byteArray);
    

    I guess sometimes the easiest solution is the right one. Not sure about the exact explanation (you can provide one, I’ll surely vote up), but this is resolved.
    Thanks anyway.

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

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here is the code from my project where I am using a datepicker. The
Here is the loop I am trying to use the map function on: volume_ids
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is the code I'm using http://jsbin.com/evike5/edit When the jQuery UI dialog is fired
Here is my javascript code for a cursor focus function to go to username
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here I am trying to change the value of the following check box while

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.