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 6818199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:08:56+00:00 2026-05-26T21:08:56+00:00

I have a user gallery at the site and it is possible for visitors

  • 0

I have a user gallery at the site and it is possible for visitors to upload some images. After upload image should be resized to some predefined presets. In addition original image should be saved too. All works fine for png and bmp image formats. But if I upload gif format or jpeg with a predominance of one color uploaded original image seems to be compressed.

For example:

Original:
Original image

Uploaded:
Uploaded image

I thorougly searched in google and found some examples how to upload image right.
At the end I have written the next method:

void UploadImagePreset(Image image, ImageFormat imgFormat, string imgPath)
{
    using (var uploadStream = imageUploader.CreateUploadStream(imagePath))
    {
        var newWidth = image.Width;
        var newHeight = image.Height;
        using (var outBitmap = new Bitmap(newWidth, newHeight))
        {
            using (var outGraph = Graphics.FromImage(outBitmap))
            {
                outGraph.CompositingQuality = CompositingQuality.HighQuality;
                outGraph.SmoothingMode = SmoothingMode.HighQuality;
                outGraph.PixelOffsetMode = PixelOffsetMode.HighQuality;
                outGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

                var imageRect = new Rectangle(0, 0, newWidth, newHeight);
                outGraph.DrawImage(image, imageRect);

                outBitmap.Save(uploadStream, imgFormat);
            }
        }
    }
}

But it did not help. Uploaded image was the same as described above.
I have tryied to specify qaulity of the results image like this:

var encoderParameters = new EncoderParameters();
var encoderParameter = new EncoderParameter(Encoder.Quality, 100);
encoderParameters.Param[0] = encoderParameter;
var encoder = ImageCodecInfo.GetImageEncoders()
    .Where(e => e.FormatID == imgFormat.Guid)
    .FirstOrDefault();
outBitmap.Save(uploadStream, encoder, encoderParameters);

It does not work too. In addition when I upload jpeg image exception occurs.

Is any way to upload image without compressing or resizing? I have spent some hours trying solve this issue and stuck on it.

  • 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-05-26T21:08:57+00:00Added an answer on May 26, 2026 at 9:08 pm

    You are passing the uploaded image through the Image class – this is a new image, based on the passed in stream.

    This is then saved using some default parameters, which would no longer reflect the original image.

    You should simply save the incoming stream directly to disk – this will result in an exact copy of the original image.

    Like this (.NET 4.0):

    using (var uploadStream = imageUploader.CreateUploadStream(imagePath))
    {
       using(var fileStream = new FileStream(imgPath, FileMode.Create))
       {
           uploadStream.CopyTo(fileStream);
       }
    }
    

    Or (pre .NET 4.0):

    using (var uploadStream = imageUploader.CreateUploadStream(imagePath))
    {
        using(var fileStream = new FileStream(imgPath, FileMode.Create))
        {
            byte[] buffer = new byte[32768];
            int read;
            while ((read = uploadStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                fileStream.Write(buffer, 0, read);
            }
        }
    }
    

    Adapted from this answer.

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

Sidebar

Related Questions

I have a UIScrollView that houses a gallery of images the user can scroll
My intention is to have the user pick an image from the gallery, then
Hi I want to show an image gallery on my site and then have
I have a site w/ an image gallery (Portfolio) page. There is drop-down navigation
I have a photo gallery I would like that every time a user does
My situation is that I have a video gallery where when a user clicks
I have user (not administrator) access to some external JMS. I'm failing to view
I have a site where I randomize the background image using a php rotator
I have gallery where user can submit Youtube links to videos and server fetches
Is it possible to get control of the android image gallery from within my

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.