I have been working on a VB6 project off and on for the past several months to allow me to preview graphic files (primarily JPG's) on the HDD as thumbnails to identify duplicates or partial images. I originally started out using the ListView control but found with a thumbnail size of 100x100 pixels, I run out of memory after ~300 files. The filesize of these jpg's is an average of 30K. The directory size is ~5MB. I also wanted to stretch the image to fit the horizontal or vertical size of the thumbnail preserving the aspect ratio. I could not find a way to accomplish this. I also wanted to do something like a tooltip to give image details when the cursor is over the thumbnail. Sample code (without the DIM's to save post space) is below:
So I investigated the use of a picturebox within a picturebox. This allows me to easily scroll the window vertically. The limitation I found with this, besides being slow, is after you reach a height of ~32K you run out of space to draw the picturebox of the next image. I am able to stretch the picture horizontally or vertically to fit the thumbnail size preserving the aspect ratio of the original image. As a bonus I get a tooltip with the picture details by resting the mouse on the thumbnail.
Is there a way around each of these limitations? I prefer to use the ListView. The objectives are: vertically scroll the thumbnails of perhaps as many as 1000-3000 images, resize the original image to maximize the horizontal OR vertical thumbnail size preserving the aspect ratio, and a tooltip feature to display the file details.
I have seen commercial and shareware programs capable of doing this in one window without resorting to next page, previous page controls. VB should be capable of doing this without me resorting to learning VC where I can control the allocation of additional memory.
Code:
Private Sub cmdImageList_Click()
ListView1.Icons = Nothing
ListView1.SmallIcons = Nothing
ListView1.ListItems.Clear
ImageList1.ListImages.Clear
ImageList1.ImageHeight = GetThumbnailsize()
ImageList1.ImageWidth = GetThumbnailsize()
ListView1.View = lvwIcon
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , "Filename", 2000
ListView1.ColumnHeaders.Add , , "X x Y", 1000
ListView1.ColumnHeaders.Add , , "Length", 1000
ListView1.ColumnHeaders.Add , , "N", 500
cntPics = 0
cntThumbs = 0
On Error Resume Next
Err.Clear
List1.Clear
List1.AddItem Dir1.Path & "\"
SSTab1.Tab = 2
i = 1
Do While List1.ListCount > 0
nextdir = List1.List(0) 'save top most element
List1.RemoveItem (0) 'do not process the same directory twice
SBar1.Panels(enmSBar1.srcpath) = nextdir
filename = Dir(nextdir & "*.jpg")
Do While filename <> ""
fname = nextdir & filename
ImageList1.ListImages.Add i, , LoadPicture(fname)
If Err.Number = 0 Then
imginfo.ReadImageInfo_2 fname
picX = imginfo.width
picY = imginfo.height
ListView1.Icons = ImageList1
Set itmX = ListView1.ListItems.Add(i, , filename, i)
itmX.SubItems(1) = Trim(Format(picX, "##,##0")) & " x " & Trim(Format(picY, "##,##0"))
itmX.SubItems(2) = Right(Space(10) & Str(FileLen(fname)), 10)
itmX.SubItems(3) = i
cntThumbs = cntThumbs + 1
SBar1.Panels(enmSBar1.Extensions) = "Pics: " & Str(cntThumbs) & " "
DoEvents
Else
SBar1.Panels(enmSBar1.Extensions) = "Pics: " & Str(cntThumbs) & "/" & Str(i) & " "
End If
filename = Dir
i = i + 1
Err.Clear
Loop 'filename <> ""
DoEvents
Loop 'list1.listcount > 0
DoEvents
Exit Sub
So I investigated the use of a picturebox within a picturebox. This allows me to easily scroll the window vertically. The limitation I found with this, besides being slow, is after you reach a height of ~32K you run out of space to draw the picturebox of the next image. I am able to stretch the picture horizontally or vertically to fit the thumbnail size preserving the aspect ratio of the original image. As a bonus I get a tooltip with the picture details by resting the mouse on the thumbnail.
Code:
Public Sub ShowPicInPic()
On Error Resume Next
PicFrame.Top = SSTab1.TabHeight + 50
VScroll1.Top = PicFrame.Top
picThumbs.Top = PicFrame.Top + 5
picThumbs.Left = PicFrame.Left + 5
picThumbs.width = PicFrame.width - 10
picThumbs.height = PicTNn(0).height
PicFrame.height = SSTab1.height - SSTab1.TabHeight - 300
VScroll1.height = PicFrame.height
VScroll1.Min = 1
VScroll1.Max = 1
startx = 0
starty = 0
currX = startx
currY = starty
i = 1
cntPics = i
cntPicsMax = i
filename = Dir(vbPicList & "*.jpg")
Do While filename <> ""
fname = vbPicList & filename
Err.Clear
Load PicTNn(i)
PicTNn(i).Picture = Nothing
If Err.Number = 0 Then
cntPics = i
If currY > picThumbs.height Then
picThumbs.height = currY + PicTNn(i).height
End If
PicTNn(i).height = GetThumbnailsize * Screen.TwipsPerPixelY
PicTNn(i).width = GetThumbnailsize * Screen.TwipsPerPixelX
PicTNn(i).Left = currX
PicTNn(i).Top = currY
PicTNn(0).Picture = LoadPicture(fname)
imginfo.ReadImageInfo_2 fname
picwidth = imginfo.width
picheight = imginfo.height
If picwidth <> 0 And picheight <> 0 Then
PicTNn(i).Visible = True
aspratio = picwidth / picheight
If aspratio < 1 Then 'height > width
scaledY = PicTNn(i).height
scaledX = scaledY * aspratio
startx = (PicTNn(i).width - scaledX) \ 2
endx = startx + scaledX
starty = 0
endy = PicTNn(i).height
Else
scaledX = PicTNn(i).width
scaledY = scaledX / aspratio
startx = 0
endx = PicTNn(i).width
starty = (PicTNn(i).height - scaledY) \ 2
endy = starty + scaledY
End If
PicTNn(i).PaintPicture PicTNn(0).Picture, startx, starty, endx - startx, endy - starty
PicTNn(i).ToolTipText = ParseFilename(fname) & Space(5) _
& Trim(Str(picwidth)) & " x " & Trim(Str(picheight)) & Space(5) _
& Format(FileLen(fname), "#,###,##0 ")
SBar1.Panels(enmSBar1.misc) = " Pics: " & Trim(Str(i)) & " "
currX = currX + PicTNn(i).width
If currX + PicTNn(i).width > SSTab1.width Then
currX = 0 'startX
currY = currY + PicTNn(i).height
VScroll1.Max = currY
End If
End If
Else
SBar1.Panels(enmSBar1.misc) = " Pics: " & Trim(Str(cntPics)) _
& "/" & Trim(Str(cntPicsMax)) & " "
End If
cntPicsMax = i
i = i + 1
filename = Dir
DoEvents
Loop
End Sub
Is there a way around each of these limitations? I prefer to use the ListView. The objectives are: vertically scroll the thumbnails of perhaps as many as 1000-3000 images, resize the original image to maximize the horizontal OR vertical thumbnail size preserving the aspect ratio, and a tooltip feature to display the file details.
I have seen commercial and shareware programs capable of doing this in one window without resorting to next page, previous page controls. VB should be capable of doing this without me resorting to learning VC where I can control the allocation of additional memory.