Anyone know of a work around in .Net to retain the highest possible resolution of a photo or image after compression or resizing?
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
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.
Here is the string we are using (C#)
Image image1 = System.Drawing.Image.FromFile(Server.MapPath(imgfilepath + actimgFilename));
Image smallimage = new Bitmap (imgNewWidth, imgNewHeight, image1.PixelFormat);
Graphics oGraphic = Graphics.FromImage(smallimage);
Rectangle oRectange = new Rectangle (0, 0, imgNewWidth, imgNewHeight);
smallimage.Save(Server.MapPath(imgfilepath + newFilename), System.Drawing.Imaging.
The only thing that you are missing is EncoderParameters. Use the above code to set quality of saved image.
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
I'm working in Excel to extract content of a table from a web page and populate Excel sheet cells with it. I'm trying to extract data from a table that gets loaded to a web page after show results method gets called. I have an error that says "Run-time error ...
When accessing from ######1.co.uk (which has an SSL) to document root ###/production everything works fine.
However when accessing ###/production from ######2.co.uk (which doesn't have an SSL - set up in the vhost file) the home page displays fine but the other pages are returning a 404.
Here's the entry in ...