Retaining highest resolution of a photo in upload?

R

RickVidallon

I have a .Net application written in C# where members may upload their
photos and have them displayed on our website. We are trying to
maintain the best quality using best settings in .Net for this.

A good commercial comparison is as follows;
I uploaded a photo to www.flickr.com. http://www.flickr.com/photos/visionefx/446635882/in/photostream/
The photo contains 73076 kbs. --- When I upload the 'same photo' to
our application it saves it at 13076 kbs. That's nice for speed but
not very good for quality.

Here is the settings we are using:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
System.Drawing.

Image image1 =
System.Drawing.Image.FromFile(Server.MapPath(imgfilepath +
actimgFilename));
System.Drawing.

Image smallimage = new Bitmap (imgNewWidth, imgNewHeight,
image1.PixelFormat);

Graphics oGraphic = Graphics.FromImage(smallimage);
oGraphic.CompositingQuality =

CompositingQuality.HighQuality;
oGraphic.SmoothingMode =

SmoothingMode.HighQuality;
oGraphic.InterpolationMode =

InterpolationMode.HighQualityBicubic;
oGraphic.PixelOffsetMode =

PixelOffsetMode.HighQuality;

Rectangle oRectange = new Rectangle (0, 0, imgNewWidth,
imgNewHeight);
oGraphic.DrawImage(image1, oRectange);

smallimage.Save(Server.MapPath(imgfilepath + newFilename),
System.Drawing.Imaging.

ImageFormat.Jpeg);
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Thanks in advance,
Rick
 
G

Guest

Hi there Rick,

In order to control the output image quality you have to use
smallImage.Save(filename, ImageCodecInfo, EncoderParameters) overload,

using System.Drawing.Imaging;

public ImageCodecInfo GetEncoder(string mimeType)
{
foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders())
{
if (String.Compare(encoder.MimeType, mimeType, true) == 0)
return encoder;
}

throw new Exception(String.Format(
"cannot find encoder for MIME type {0}", mimeType);
}

and amend the method where you save transformed image:

long quality = 75L; // from 1 to 100
ImageCodecInfo encoder = GetEncoder("image/jpeg");
EncoderParameters parameters = new EncoderParameters(1);
parameters.Param[0] = new EncoderParameter(Encoder.Quality, quality);

smallImage.Save(Server.MapPath(imgfilepath + newFilename), encoder,
parameters);

hope this helps
 
G

Guest

Actually, depending on the image type, the most reliable way to "preserve
everything" is to save the entire byte stream using a FileStream and write it
to a file. In the case of Tiff images, for example, using one of the
Image.Save overloads will still lose information, due to a "not 100%
complete" implementation by Microsoft.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top