944,150 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 2382
  • ASP.NET RSS
Apr 4th, 2007
0

Retaining highest res. of a photo in upload?

Expand Post »
Anyone know of a work around in .Net to retain the highest possible resolution of a photo or image after compression or resizing?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
rickvidallon is offline Offline
48 posts
since May 2006
Apr 5th, 2007
0

Re: Retaining highest res. of a photo in upload?

Use this code:

ASP.NET Syntax (Toggle Plain Text)
  1. Dim g As Graphics = Graphics.FromImage(YourBitmap)
  2.  
  3. g.SmoothingMode = SmoothingMode.HighQuality
  4. g.InterpolationMode = InterpolationMode.HighQualityBicubic
  5. g.PixelOffsetMode = PixelOffsetMode.HighQuality

And when saving use this:

ASP.NET Syntax (Toggle Plain Text)
  1. Dim myParams As EncoderParameters = New EncoderParameters(1)
  2. myParams.Param(0) = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80)
  3. YourBitmap.Save(YourPath, GetEncoderInfo(MimeType), myParams)

This is GetEncoderInfo function:

ASP.NET Syntax (Toggle Plain Text)
  1. Public Function GetEncoderInfo(ByVal MimeType As String) As ImageCodecInfo
  2. Dim j As Integer
  3. Dim encoders As ImageCodecInfo()
  4. encoders = ImageCodecInfo.GetImageEncoders()
  5. j = 0
  6. Do While j < encoders.Length
  7. If encoders(j).MimeType = MimeType.Trim.Replace("pjpeg", "jpeg") Then
  8. Return encoders(j)
  9. End If
  10. j += 1
  11. Loop
  12. Return Nothing
  13. End Function
Last edited by ManicCW; Apr 5th, 2007 at 4:01 am.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
ManicCW is offline Offline
95 posts
since Nov 2005
Apr 5th, 2007
0

Re: Retaining highest res. of a photo in upload?

Wow- that was quick. I am a designer researching this for my programmer -- who is too slammed to research this. We are trying to keep the highest quality for uploaded photos, much like www.flickr.com does for it's members.

When you upload a 4000px by 2000px 5 meg image to (Flickr) it will compress to 1/2 or 2.5 meg and display at the appropriate aspect ratio for their site.

Our .Net app is compressing the photo file sizes much smaller, where as uploading a test photo to Flickr will sace at 58760 Kb our app. will save the same photo at 17240 Kb.

I will share your feedback with him. Thank you for taking the time to reply. It is greatly appreciated.

Rick
Reputation Points: 10
Solved Threads: 0
Light Poster
rickvidallon is offline Offline
48 posts
since May 2006
Apr 7th, 2007
0

Re: Retaining highest res. of a photo in upload?

ManicCW

Here is the string we are using (C#)

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);
Reputation Points: 10
Solved Threads: 0
Light Poster
rickvidallon is offline Offline
48 posts
since May 2006
Apr 10th, 2007
0

Re: Retaining highest res. of a photo in upload?

The only thing that you are missing is EncoderParameters. Use the above code to set quality of saved image.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
ManicCW is offline Offline
95 posts
since Nov 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: little help in siteMap!!!!plz!
Next Thread in ASP.NET Forum Timeline: An unhandled exception of type 'System.Net.Sockets.SocketException' error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC