The dpi resolution is just a pair of numbers stored in the file. Changing them doesn't have a direct effect on the image display size or quality. But there is another factor which does affect quality. That is the jpeg compression quality (%). Changing that compression affects both the clarity of the image and the size of the file. It depends a bit on the image, but decreasing the jpeg quality can often lead to a big saving in file size without much visible deterioration.
In your program, you probably you need to use compression quality in combination with changing the pixel size in order to optimize the file size. Here's a method to save an image as a jpeg file with a chosen compression quality:
I think you can afford to ignore the dpi resolution for your present purposes. Or at most, use it to calculate a desired print size in inches instead of a pixel size.Code:Imports System.Drawing.Imaging '.... Dim jpegCodec As ImageCodecInfo Public Sub Save(ByVal path As String, ByVal img As Image, ByVal quality As Integer) If quality <= 0 Then quality = 0 : If quality >= 100 Then quality = 100 Dim qParam As New EncoderParameter(Encoder.Quality, quality) If jpegCodec Is Nothing Then jpegCodec = ImageCodecInfo.GetImageEncoders.Where _ (Function(e As ImageCodecInfo) e.MimeType = "image/jpeg")(0) End If Dim encoderParams As New EncoderParameters(1) encoderParams.Param(0) = qParam Try img.Save(path, jpegCodec, encoderParams) Catch MessageBox.Show("Unable to save PNG image to path " & path) End Try End Sub
BB




Reply With Quote
