locked
GetThumbnailImage Losing Quality RRS feed

  • Question

  • User274838862 posted
    When I save a file using the code below, I load the image back in and do a resize, but I lose alot of quality from the image. Does anyone know of a setting to alter this from happening? Dim strFileName As String = file_upload.PostedFile.FileName strFileName = Path.GetFileName(strFileName) If File.Exists(rootpath & strFileName) Then lblUploadResult.Text = strFileName & " already exists on the server!" Else file_upload.PostedFile.SaveAs(rootpath & strFileName) lblUploadResult.Text = strFileName & " has been successfully uploaded." orginalimg = orginalimg.FromFile(rootpath & strFileName) width = orginalimg.Width height = orginalimg.Height If rdoSize.SelectedValue <> "0" Then ratio = width / CInt(rdoSize.SelectedValue) NewWidth = CInt(rdoSize.SelectedValue) NewHeight = height / ratio Else NewWidth = width NewHeight = height End If thumb = orginalimg.GetThumbnailImage(NewWidth, NewHeight, Nothing, inp) orginalimg.Dispose() thumb.Save(rootpath & strFileName) thumb.Dispose() End If Thanks
    Monday, December 6, 2004 2:53 AM

All replies

  • User-960547388 posted
    By default JPEG compression is set to a pretty high value, so you get bad quality. It is possible to set a custom level of compression Image PreviewImage = System.Drawing.Image.FromFile(@"c:\input.jpg"); ImageCodecInfo[] icf = ImageCodecInfo.GetImageEncoders(); // get available codecs EncoderParameters encps = new EncoderParameters(1); EncoderParameter encp = new EncoderParameter (Encoder.Quality, 75); // Set quality to 75 encps.Param[0] = encp; PreviewImage.Save(@"c:\output.jpg", icf[1], encps); // icf[1] = JPEG Codec Let me know if it worked. thnx
    Monday, December 6, 2004 4:16 PM