Thanks Alexy,
this got me on the right track but my image is still more grainy than if I
do it in something like corel photopaint.
Here is my code below. Perhaps I have a logical error somehwere ?
Take note of the 1000L ...if I put 100L or anything higher it does not get
better, but a value of 0 is really really grainy...so I was hoping this
was some kind of a weird calculated value.
Private Sub generateThumbnail(ByVal filepath As String, ByVal FileName
As String)
'Create a new Bitmap Image loading from location of origional file
'Dim bm As Bitmap = System.Drawing.Image.FromFile(filepath &
FileName)
Dim jpg As System.Drawing.Image =
System.Drawing.Image.FromFile(filepath & FileName)
'Declare Thumbnails Height and Width
Dim newWidth As Integer = 125
'Dim newHeight As Integer = (newWidth / bm.Width) * bm.Height
Dim newHeight As Integer = (newWidth / jpg.Width) * jpg.Height
Dim resizedBMP As Bitmap = New Bitmap(jpg, newWidth, newHeight)
' Prepare for a controlled-quality JPEG
Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")
Dim jpegEncoder As Encoder = Encoder.Quality
Dim jpegEncoderParameters As New EncoderParameters(1)
Dim jpegEncoderQuality As New EncoderParameter(jpegEncoder, 1000L)
jpegEncoderParameters.Param(0) = jpegEncoderQuality
'Dim thumbnailPath As String
' some path to save your JPEG to
Dim newStrFileName As String = filepath & "ThumbNails/" & FileName
resizedBMP.Save(newStrFileName, jpegCodec, jpegEncoderParameters)
End Sub
Private Function GetEncoderInfo(ByVal mimeType As String) _
As ImageCodecInfo
Dim j As Integer
Dim encoders As ImageCodecInfo()
encoders = ImageCodecInfo.GetImageEncoders()
For j = 0 To encoders.Length
If encoders(j).MimeType = mimeType Then
Return encoders(j)
End If
Next j
Return Nothing
End Function
Miro
I found this - but I cant seem to convert it to vb.
// Prepare for a controlled-quality JPEG
exportImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
Encoder jpegEncoder = Encoder.Quality;
EncoderParameters jpegEncoderParameters = new EncoderParameters(1);
EncoderParameter jpegEncoderQuality = new EncoderParameter(jpegEncoder,
jpegQuality);
jpegEncoderParameters.Param[0] = jpegEncoderQuality;string thumbnailPath;
// some path to save your JPEG to
thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters);
I found this link to create a thumbnail image.
http://forums.asp.net/t/739822.aspx
But the thumbnail image looks grainy.
If I take the same image, resample it in corel photopaint at 72dpi, the
image is nice and small and not grainy at all ( sharp ).
I was wondering if there is anything else that can be done to a jpg as
you
are compressing it down to a smaller jpg, so you do not end up with a
grainy image.
Miro
' Prepare for a controlled-quality JPEG
Dim jpegCodec As exportImageCodecInfo = GetEncoderInfo("image/jpeg")
Dim jpegEncoder As Encoder = Encoder.Quality
Dim jpegEncoderParameters As New EncoderParameters(1)
Dim jpegEncoderQuality As New EncoderParameter(jpegEncoder,
jpegQuality)
jpegEncoderParameters.Param(0) = jpegEncoderQuality
Dim thumbnailPath As String
' some path to save your JPEG to
thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters)