473,657 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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( imgfilepath +
actimgFilename) );
System.Drawing.

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

Graphics oGraphic = Graphics.FromIm age(smallimage) ;
oGraphic.Compos itingQuality =

CompositingQual ity.HighQuality ;
oGraphic.Smooth ingMode =

SmoothingMode.H ighQuality;
oGraphic.Interp olationMode =

InterpolationMo de.HighQualityB icubic;
oGraphic.PixelO ffsetMode =

PixelOffsetMode .HighQuality;

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

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

ImageFormat.Jpe g);
::::::::::::::: ::::::::::::::: ::::::::::::::: :::::::::::
Thanks in advance,
Rick

Apr 8 '07 #1
2 2010
Hi there Rick,

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

using System.Drawing. Imaging;

public ImageCodecInfo GetEncoder(stri ng mimeType)
{
foreach (ImageCodecInfo encoder in ImageCodecInfo. GetImageEncoder s())
{
if (String.Compare (encoder.MimeTy pe, mimeType, true) == 0)
return encoder;
}

throw new Exception(Strin g.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("ima ge/jpeg");
EncoderParamete rs parameters = new EncoderParamete rs(1);
parameters.Para m[0] = new EncoderParamete r(Encoder.Quali ty, quality);

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

hope this helps

--
Milosz
"RickVidall on" 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( imgfilepath +
actimgFilename) );
System.Drawing.

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

Graphics oGraphic = Graphics.FromIm age(smallimage) ;
oGraphic.Compos itingQuality =

CompositingQual ity.HighQuality ;
oGraphic.Smooth ingMode =

SmoothingMode.H ighQuality;
oGraphic.Interp olationMode =

InterpolationMo de.HighQualityB icubic;
oGraphic.PixelO ffsetMode =

PixelOffsetMode .HighQuality;

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

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

ImageFormat.Jpe g);
::::::::::::::: ::::::::::::::: ::::::::::::::: :::::::::::
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


"RickVidall on" 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( imgfilepath +
actimgFilename) );
System.Drawing.

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

Graphics oGraphic = Graphics.FromIm age(smallimage) ;
oGraphic.Compos itingQuality =

CompositingQual ity.HighQuality ;
oGraphic.Smooth ingMode =

SmoothingMode.H ighQuality;
oGraphic.Interp olationMode =

InterpolationMo de.HighQualityB icubic;
oGraphic.PixelO ffsetMode =

PixelOffsetMode .HighQuality;

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

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

ImageFormat.Jpe g);
::::::::::::::: ::::::::::::::: ::::::::::::::: :::::::::::
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
3422
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 amount and also linked to shopping cart. If anyone knows where I can find or purchase such code please let me know. bernie@znservices.com
10
2872
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 write.... any ideas why?? <?php include 'gall_settings.inc';
2
1965
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 information of the photo and set up a folder to store the "PHOTOs". and design a web page to show. My question is how to put the photo on the web page.
5
3241
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 want to resize the image before I save it... How do I take the uploaded .jpg and shrink it to a thumbnail? How do I pass the uploaded .jpg to a stored procedure that will store the image as an image datatype in SQL Server 2000? I'm developing this...
3
2463
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 on a page and clicking on the thumbnails would pop open another window with the full-sized image. The site needs a form that provides for uploading photos. The photo gallery can be limited to a certain number of photos if need be. What are the...
3
2549
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 have links to allow the user to rotate the photo 90 degrees left or right. After I rebind the datalist,the photo is not rotated on the web page, although it correctly rotated on the server. If I click refresh, it updates, but calling refresh causes...
1
5990
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 want to add the photo upload option in the save and edit form. looking forward to a quick reaply. thank you fariba
1
1926
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. 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...
1
3601
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 that uploads to photo to the folder in the site root diorectory. One that uploads the info to mysql database. but... When I try to upload them both ways at the same time i cant get it. I am Including code for both pages i have working. Code for...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.