by Mohd Muzaffar Zargar (1 Submission)
Category: Graphics
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 4th September 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code generates a thumbnail of a picture in most easy way. No API or OCX is used.
API Declarations
Please note that you must have the AUTOREDRAW property for the picturebox showing the thumbnail set to TRUE
'In my program "picThumb" is the picturebox to display the thumnail while as 'pic1 is the hidden picturebox to load pictures
Private Sub thumbGenerateStatus()
'On Error Resume Next
'Generate thumbnail images of larger images
Dim dw, sw, dh, sh, newsh, newsw
picThumb.Cls
sw = pic1.Width
sh = pic1.Height
dw = picThumb.Width
dh = picThumb.Height
If pic1.Height < picThumb.Height And pic1.Width < picThumb.Width Then
Dim centerX, centerY As Integer
'if Source picture is smaller than the destination thumnail then just paint and center it on thumnail
centerX = (picThumb.Width - pic1.Width) / 2
centerY = (picThumb.Height - pic1.Height) / 2
picThumb.PaintPicture pic1.Picture, centerX, centerY
newsw = pic1.Picture.Width
newsh = pic1.Picture.Height
Else 'If the source dimensions are bigger than the thumbnail then adjust the height and with proportionately
If sw > sh Then
newsw = dw
newsh = Round(sh * (dw / sw))
If newsh > dh Then
newsh = dh
newsw = (sw * (dh / sh))
End If
Else
newsh = dh
newsw = Round(sw * (dh / sh))
If newsw > dw Then
newsw = dw
newsh = (sh * (dw / sw))
End If
End If
Dim dx, dy
picThumb.Picture = LoadPicture()
picThumb.PaintPicture pic1.Picture, Round((dw - newsw) / 2), Round((dh - newsh) / 2), Round(newsw), Round(newsh)
End If
pic1.Picture = LoadPicture()
End Sub
Thanx.
No comments have been posted about This code generates a thumbnail of a picture in most easy way. No API or OCX is used.. Why not be the first to post a comment about This code generates a thumbnail of a picture in most easy way. No API or OCX is used..