473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Retaining highest resolution of a photo in upload?

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/visione...n/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(imgfi lepath +
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

Apr 8 '07 #1
2 1998
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

--
Milosz
"RickVidallon" wrote:
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/visione...n/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(imgfi lepath +
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

Apr 9 '07 #2
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"RickVidallon" wrote:
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/visione...n/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(imgfi lepath +
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

Apr 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bernie | last post by:
I would like to know where I can obtain code (php) to upload photos to a server with payment options. I am designing a photographic site where people can upload photos, pick the print size and...
10
by: matt | last post by:
I have this code, works perfectly on Windows server, but now i'm trying to run it on a Linux server, the form submits, i get no errors, but the photo doesnt upload, and the caption file doesnt...
2
by: Tony WONG | last post by:
i am not sure that this subject can be discussed here. i have many photos. they are stored according to the name of the EVENT and YEAR. i will set up a database (sql or access) to store...
5
by: bob garbados | last post by:
I am trying to create a database-driven photo gallery for a friend with an admin form to upload images... I can upload a file to the web server, but I want to store the image in a database and I...
3
by: bob garbados | last post by:
I'm looking for thoughts on photo galleries and security/performance implications... I'm working on an asp.net site in vb that will include an updateable photo gallery that will display thumbnails...
3
by: byrd48 | last post by:
Hi, I am developing a web site which allows users to upload and share photos. I have a datalist which lists the photos and has the usual edit, update commands. Within the edititemtemplate, I...
1
by: fariba123 | last post by:
hi i am working with php. i am designing a site which will store employee information along with his/her photo and also edit information. i have completed the information save and edit part. now i...
1
rickvidallon
by: rickvidallon | last post by:
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....
1
by: cumupkid | last post by:
II am trying to create a form that will allow me to upload photos to a folder in the site root directory and add the information to the mysql db at the same time. I have created two forms, one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.