T
Trint Smith
How can I show image thumbnail??
thanks,
Trint
..Net programmer
(e-mail address removed)
thanks,
Trint
..Net programmer
(e-mail address removed)
Trint Smith said:How can I show image thumbnail??
thanks,
Trint
Rimu Atkinson said:i made this class which uses the method that the other people suggested.
usage:
dim x as new ImageResizer
x.sourcefilename = "c:\whatever.jpg"
x.newwidth = 40 'you can specify either or both of newwidth and newheight
x.saveas("c:\filename.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
easy, huh?
Imports System.Drawing.Imaging
'this class was written by Rimu Atkinson on 2nd December 2002
'feel free to use this code for whatever purposes you like, but i'd
appreciate it if you kept this comment block in
Public Class ImageResizer
Private m_FileName As String
Public NewWidth As Integer = 0
Public NewHeight As Integer = 0
Property SourceFilename() As String 'the input file
Get
Return m_FileName
End Get
Set(ByVal Value As String)
Dim f As System.IO.File
If f.Exists(Value) Then
m_FileName = Value
Else
m_FileName = vbNullString
End If
End Set
End Property
Public Function SaveAs(ByVal ThumbFileName As String, ByVal FileType As
ImageFormat) As Boolean
Dim img As Bitmap
Dim ThumbNail As Bitmap
Dim callbackdata As IntPtr
Dim ratio As Single
Dim myImageCodecInfo As ImageCodecInfo, myEncoder As Encoder,
myEncoderParameters As EncoderParameters
Dim myEncoderParameter As EncoderParameter
If NewWidth = 0 And NewHeight = 0 Then Return False
If m_FileName = vbNullString Then Return False
myImageCodecInfo = GetEncoderInfo("image/jpeg")
myEncoder = Encoder.Quality
myEncoderParameters = New EncoderParameters(1)
myEncoderParameter = New EncoderParameter(myEncoder, 65)
myEncoderParameters.Param(0) = myEncoderParameter
img = New Bitmap(m_FileName)
'don't ask me why, but rotating the image 360 degrees improves the quality
no end!
img.RotateFlip(RotateFlipType.Rotate180FlipNone)
img.RotateFlip(RotateFlipType.Rotate180FlipNone)
If NewWidth <> 0 And NewHeight <> 0 Then
ThumbNail = img.GetThumbnailImage(NewWidth, NewHeight, AddressOf
AbortHandler, callbackdata)
ElseIf NewWidth <> 0 And NewHeight = 0 Then
ratio = NewWidth / img.Width
ThumbNail = img.GetThumbnailImage(NewWidth, img.Height * ratio, AddressOf
AbortHandler, callbackdata)
ElseIf NewWidth = 0 And NewHeight <> 0 Then
ratio = NewHeight / img.Height
ThumbNail = img.GetThumbnailImage(img.Width * ratio, NewHeight, AddressOf
AbortHandler, callbackdata)
End If
ThumbNail.Save(ThumbFileName, myImageCodecInfo, myEncoderParameters)
img.Dispose()
Return True
End Function
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
Return Nothing
End Function
Private Function AbortHandler() As Boolean
'whatever.
End Function
End Class
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.