Hi Guys,
Im using this code to resize images:
when I use my class I pass 208 as the width and height. My images are resized fine. Say I get an image with the dimensions 394x394 and a size of 97kb.Code:Public Class RJpeg Private mFileName As String Private mWidth As Integer Private mHeight As Integer Public Property FileName() As String Get Return mFileName End Get Set(ByVal Value As String) mFileName = Value End Set End Property Public Property NewWidth() As Integer Get Return mWidth End Get Set(ByVal value As Integer) mWidth = value End Set End Property Public Property NewHeight() As Integer Get Return mHeight End Get Set(ByVal value As Integer) mHeight = value End Set End Property Public Sub New() mHeight = 0 mWidth = 0 mFileName = "" End Sub Public Sub ResizeImage() Dim imgOriginal As Image Dim OriginalHeight As Single Dim OriginalWidth As Single Dim NewWidth As Integer Dim NewHeight As Integer Dim ResizedBitmap As Bitmap Dim ResizedImage As Graphics Dim quality As Long = 40 Dim qualityparam As New EncoderParameter(Encoder.Quality, quality) Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg") Dim encoderParams As New EncoderParameters(1) encoderParams.Param(0) = qualityparam imgOriginal = Image.FromFile(mFileName) OriginalHeight = imgOriginal.Height OriginalWidth = imgOriginal.Width ' Finds height and width of resized image If (OriginalHeight > OriginalWidth) Then NewHeight = mHeight NewWidth = mWidth '((OriginalWidth / OriginalHeight) * NewImageSize) Else NewWidth = mWidth NewHeight = mHeight '((OriginalHeight / OriginalWidth) * NewImageSize) End If ' Create new bitmap that will be used for resized image ResizedBitmap = New Bitmap(NewWidth, NewHeight) ResizedImage = Graphics.FromImage(ResizedBitmap) ' Resized image will have best possible quality ResizedImage.InterpolationMode = InterpolationMode.HighQualityBicubic ResizedImage.CompositingQuality = CompositingQuality.HighQuality ResizedImage.SmoothingMode = SmoothingMode.HighQuality ' Draw resized image ResizedImage.DrawImage(imgOriginal, 0, 0, NewWidth, NewHeight) ' Save thumbnail to file imgOriginal.Dispose() ResizedBitmap.Save(mFileName, jpegCodec, encoderParams) ' It is important to take care of memory, especially in cases ' when code works with graphics ResizedBitmap.Dispose() ResizedImage.Dispose() End Sub Private Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders For i As Integer = 0 To codecs.Length - 1 If codecs(i).MimeType = mimeType Then Return codecs(i) End If Next Return Nothing End Function
After I resize it's dimensions are 208x208 and the size is 56kb.
I need to reduce the size of the jpeg even more to say 15kb. How can I do this?
Also, when I open the jpeg in photoshop it says "Invalid JPEG marker type". Any idea why this would happen? Please help




Reply With Quote