DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   Retaining highest res. of a photo in upload? (http://www.daniweb.com/forums/thread74251.html)

rickvidallon Apr 4th, 2007 11:27 pm
Retaining highest res. of a photo in upload?
 
Anyone know of a work around in .Net to retain the highest possible resolution of a photo or image after compression or resizing?

ManicCW Apr 5th, 2007 4:00 am
Re: Retaining highest res. of a photo in upload?
 
Use this code:

Dim g As Graphics = Graphics.FromImage(YourBitmap)

g.SmoothingMode = SmoothingMode.HighQuality
g.InterpolationMode = InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = PixelOffsetMode.HighQuality

And when saving use this:

Dim myParams As EncoderParameters = New EncoderParameters(1)
myParams.Param(0) = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80)
YourBitmap.Save(YourPath, GetEncoderInfo(MimeType), myParams)

This is GetEncoderInfo function:

Public Function GetEncoderInfo(ByVal MimeType As String) As ImageCodecInfo
        Dim j As Integer
        Dim encoders As ImageCodecInfo()
        encoders = ImageCodecInfo.GetImageEncoders()
        j = 0
        Do While j < encoders.Length
            If encoders(j).MimeType = MimeType.Trim.Replace("pjpeg", "jpeg") Then
                Return encoders(j)
            End If
            j += 1
        Loop
        Return Nothing
End Function

rickvidallon Apr 5th, 2007 11:36 am
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

rickvidallon Apr 7th, 2007 6:01 pm
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);

ManicCW Apr 10th, 2007 7:20 am
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.


All times are GMT -4. The time now is 4:27 am.

Forum system based on vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©2003 - 2010 DaniWeb® LLC