Retaining highest res. of a photo in upload?

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 48
Reputation: rickvidallon is an unknown quantity at this point 
Solved Threads: 0
rickvidallon's Avatar
rickvidallon rickvidallon is offline Offline
Light Poster

Retaining highest res. of a photo in upload?

 
0
  #1
Apr 4th, 2007
Anyone know of a work around in .Net to retain the highest possible resolution of a photo or image after compression or resizing?
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

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

 
0
  #2
Apr 5th, 2007
Use this code:

  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:

  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 48
Reputation: rickvidallon is an unknown quantity at this point 
Solved Threads: 0
rickvidallon's Avatar
rickvidallon rickvidallon is offline Offline
Light Poster

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

 
0
  #3
Apr 5th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 48
Reputation: rickvidallon is an unknown quantity at this point 
Solved Threads: 0
rickvidallon's Avatar
rickvidallon rickvidallon is offline Offline
Light Poster

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

 
0
  #4
Apr 7th, 2007
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);
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

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

 
0
  #5
Apr 10th, 2007
The only thing that you are missing is EncoderParameters. Use the above code to set quality of saved image.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC