From: k_zeon on
Hi

I have made a small a program that lists jpg picture files ie app.path &
"\testfolder\Image1.jpg" in a grid 2,3,4 etc etc
I need to use a Listview to show thumbnails of each picture. (or if there is
a free alternative would be interested)
At present i am using GDI+ to resize pics on the fly and load them into an
Imagelist
I can then assign them to the Listview and display them.

As a test i tried loading 500 images and I get an error. 'Out of Memory'.
the max i can load is 350 with out any error.

So what i have now decieded is to show 50 or 100 at a time.

I am struggling on how to do this.

Below is the code I have now. (not very good i'm afraid) just for testing i
am using 3 images at a time.

Any help would be great

Thanks in advance.

Private Sub Command3_Click()
If DontGoForward = True Then Exit Sub ' this is set when i reach the end


Dim Token As Long


If PicsLoading = True Then
PicsLoading = False
EndImageNumber = 2
Else

StartImageNumber = EndImageNumber + 1
EndImageNumber = EndImageNumber + 3
If StartImageNumber <= List1.ListCount - 1 Then

Else
Exit Sub
End If
End If


lblstart.Caption = StartImageNumber
lblend.Caption = EndImageNumber


' Clear the controls
Set ListView1.Icons = Nothing
ListView1.ListItems.Clear
ImageList1.ListImages.Clear

' Initialise GDI+
Token = InitGDIPlus

Dim X As Integer
If EndImageNumber > List1.ListCount - 1 Then
EndImageNumber = List1.ListCount - 1
DontGoForward = True
End If
For X = StartImageNumber To EndImageNumber

Call AddPic(List1.List(X), "Movie 1") '<<<< this just calls a sub to
resize pic and place in imagelist for listview to use.

Next X

' Free GDI+
FreeGDIPlus Token

ListView1.Arrange = lvwAutoTop
ListView1.Refresh


End Sub

From: duke on
On Nov 12, 2:33 pm, "k_zeon" <silvermaine2...(a)googlemail.com> wrote:
> Hi
>
> I have made a small a program that lists jpg picture files  ie  app.path &
> "\testfolder\Image1.jpg" in a grid   2,3,4 etc etc
> I need to use a Listview to show thumbnails of each picture. (or if there is
> a free alternative would be interested)
> At present i am using GDI+ to resize pics on the fly and load them into an
> Imagelist
> I can then assign them to the Listview  and display them.
>
> As a test i tried loading 500 images and I get an error.  'Out of Memory'.
> the max i can load is 350 with out any error.
>
> So what i have now decieded is to show 50 or 100 at a time.
>
> I am struggling on how to do this.
>
> Below is the code I have now. (not very good i'm afraid) just for testing i
> am using 3 images at a time.
>
> Any help would be great
>
> Thanks in advance.
>
> Private Sub Command3_Click()
>     If DontGoForward = True Then Exit Sub ' this is set when i reach the end
>
>     Dim Token As Long
>
>     If PicsLoading = True Then
>         PicsLoading = False
>         EndImageNumber = 2
>     Else
>
>         StartImageNumber = EndImageNumber + 1
>         EndImageNumber = EndImageNumber + 3
>         If StartImageNumber <= List1.ListCount - 1 Then
>
>         Else
>             Exit Sub
>         End If
>     End If
>
>     lblstart.Caption = StartImageNumber
>     lblend.Caption = EndImageNumber
>
>     ' Clear the controls
>     Set ListView1.Icons = Nothing
>     ListView1.ListItems.Clear
>     ImageList1.ListImages.Clear
>
>     ' Initialise GDI+
>     Token = InitGDIPlus
>
>     Dim X As Integer
>     If EndImageNumber > List1.ListCount - 1 Then
>         EndImageNumber = List1.ListCount - 1
>         DontGoForward = True
>     End If
>     For X = StartImageNumber To EndImageNumber
>
>         Call AddPic(List1.List(X), "Movie 1") '<<<< this just calls a sub to
> resize pic and place in imagelist for listview to use.
>
>     Next X
>
>     ' Free GDI+
>     FreeGDIPlus Token
>
>     ListView1.Arrange = lvwAutoTop
>     ListView1.Refresh
>
> End Sub

I have created a "Photo Book" program that accomplishes what you are
attempting, except I simply use an array of image controls. instead of
using Listview. The program has become very elaborate and would be
impossible for me to post sections of it and still make sense for
someone to follow, besides some may criticize my programming
techniques as being unorthodoxed but it works for me.
I have been able to display over 600 images on my Benq monitor that
has a 1280 X 1024 resolution and over 800 thumbnails on my son's 24
inch monitor without any problems.

I therefore offer some very general suggestions that I used:

I prefer to use the image control for this purpose as it is extremely
simple to resize the thumbnails to whatever I want with the "stretch"
property.
Assuming you are displaying pictures from a digital camera, you are
aware that all digital cameras ( all that I have worked with ) are
have EXIF headers which have all pertinent information about the
picture and embed a thumbnail usually 160 X 120 which can be
extracted, and loaded into in your listview, or I use it to load my
image control array.

I hope I have offered you some food for thought...... Best of Luck.

Duke
From: k_zeon on
Hi Duke

I have just finished making my own usercontrol to display a picture (aprox
inch & half wide and 2inch high.
I can load them up now no problem, except one.

the Picturebox that i use to display the usercontrol has a maximum height of
245745 so when i show more pics they dont get shown at the bottom.
I use a scollbar to scroll down and then get the the limit that the picture
box gets to.

I am there fore back to the problem I had before of showing say 100 at a
time and having a Back & Forward button.

I will have another go at coding this. ie Click forward and the next 100
gets shown and vice versa.

I got stuck when i reach the end and the count does not reach the 100 mark.
ie it gets to say 63.
Now when I click the back button I want to go back the 63 first and then 100
thereafter

any snippet of code that could help would be much appreciated.

thanks


Garry

"duke" <nospama(a)3web.net> wrote in message
news:6a150fff-ef37-455d-8c42-66ae3c44bb9b(a)s31g2000yqs.googlegroups.com...
> On Nov 12, 2:33 pm, "k_zeon" <silvermaine2...(a)googlemail.com> wrote:
>> Hi
>>
>> I have made a small a program that lists jpg picture files ie app.path
>> &
>> "\testfolder\Image1.jpg" in a grid 2,3,4 etc etc
>> I need to use a Listview to show thumbnails of each picture. (or if there
>> is
>> a free alternative would be interested)
>> At present i am using GDI+ to resize pics on the fly and load them into
>> an
>> Imagelist
>> I can then assign them to the Listview and display them.
>>
>> As a test i tried loading 500 images and I get an error. 'Out of
>> Memory'.
>> the max i can load is 350 with out any error.
>>
>> So what i have now decieded is to show 50 or 100 at a time.
>>
>> I am struggling on how to do this.
>>
>> Below is the code I have now. (not very good i'm afraid) just for testing
>> i
>> am using 3 images at a time.
>>
>> Any help would be great
>>
>> Thanks in advance.
>>
>> Private Sub Command3_Click()
>> If DontGoForward = True Then Exit Sub ' this is set when i reach the
>> end
>>
>> Dim Token As Long
>>
>> If PicsLoading = True Then
>> PicsLoading = False
>> EndImageNumber = 2
>> Else
>>
>> StartImageNumber = EndImageNumber + 1
>> EndImageNumber = EndImageNumber + 3
>> If StartImageNumber <= List1.ListCount - 1 Then
>>
>> Else
>> Exit Sub
>> End If
>> End If
>>
>> lblstart.Caption = StartImageNumber
>> lblend.Caption = EndImageNumber
>>
>> ' Clear the controls
>> Set ListView1.Icons = Nothing
>> ListView1.ListItems.Clear
>> ImageList1.ListImages.Clear
>>
>> ' Initialise GDI+
>> Token = InitGDIPlus
>>
>> Dim X As Integer
>> If EndImageNumber > List1.ListCount - 1 Then
>> EndImageNumber = List1.ListCount - 1
>> DontGoForward = True
>> End If
>> For X = StartImageNumber To EndImageNumber
>>
>> Call AddPic(List1.List(X), "Movie 1") '<<<< this just calls a sub
>> to
>> resize pic and place in imagelist for listview to use.
>>
>> Next X
>>
>> ' Free GDI+
>> FreeGDIPlus Token
>>
>> ListView1.Arrange = lvwAutoTop
>> ListView1.Refresh
>>
>> End Sub
>
> I have created a "Photo Book" program that accomplishes what you are
> attempting, except I simply use an array of image controls. instead of
> using Listview. The program has become very elaborate and would be
> impossible for me to post sections of it and still make sense for
> someone to follow, besides some may criticize my programming
> techniques as being unorthodoxed but it works for me.
> I have been able to display over 600 images on my Benq monitor that
> has a 1280 X 1024 resolution and over 800 thumbnails on my son's 24
> inch monitor without any problems.
>
> I therefore offer some very general suggestions that I used:
>
> I prefer to use the image control for this purpose as it is extremely
> simple to resize the thumbnails to whatever I want with the "stretch"
> property.
> Assuming you are displaying pictures from a digital camera, you are
> aware that all digital cameras ( all that I have worked with ) are
> have EXIF headers which have all pertinent information about the
> picture and embed a thumbnail usually 160 X 120 which can be
> extracted, and loaded into in your listview, or I use it to load my
> image control array.
>
> I hope I have offered you some food for thought...... Best of Luck.
>
> Duke

From: Larry Serflaten on

"k_zeon" <silvermaine2000(a)googlemail.com> wrote

> any snippet of code that could help would be much appreciated.

Here is a rough cut of a thumbnail viewer. Its rough in that extracting
the thumbnail is not optimized and it takes over the CPU when it needs
to load images. It could be improved by using a timer to control the
loading of images such that they load even while the user isn't doing
anything. As it is, the images only load if they are needed for display.
Because of that, every time you go to a page that you haven't been to
before, the images have to load and will hog the CPU until the page
is filled. You should be aware, if your pictures are large files, just
loading them into memory is going to take some amount of time
due to disk access delays.

But this is an example of how you can store your thumbnails in an
array such that you only store the thumbnail image. I've tested it
to over 1000 images and it still had room for more.

Have a look, use as you see fit.....

To a new form, add a FileListBox, a Picturebox, and a Vertical
ScrollBar. (For ease of use I use a hidden FileListBox to get the
file names) Paste in the code below and change the AddPath call
to a valid folder on your system.

To load up the array quickly, maximize the form, and step down a
page at a time. When you get to the bottom, the array will be filled
and you can then see how it adjusts to resizing and such.

Have fun!
LFS

Option Explicit
Private Type ThumbNails
Image As StdPicture
Name As String
End Type

Private THM() As ThumbNails
Private Dummy As StdPicture
Private TopIndex As Long
Private ListCount As Long
Private ShowCols As Long
Private ShowRows As Long

Private Sub Form_Load()
InitializeForm
' Add one or more paths to be displayed
AddPath 'USE A VALID FOLDER NAME HERE'
End Sub

Private Sub Form_Paint()
UpdateThumbs
End Sub

Private Sub VScroll1_Change()
TopIndex = VScroll1.Value * ShowCols
UpdateThumbs
End Sub

Private Sub VScroll1_GotFocus()
File1.SetFocus
End Sub

Private Sub Form_Resize()
Dim cols&, rows As Long
Dim stepX As Long, stepY As Long
' Adjust scroll bar to right edge of form
VScroll1.Move ScaleWidth - 240, 0, 240, ScaleHeight
' Calculate number of cols and rows
stepX = Picture1.Width + 30
stepY = Picture1.Height + 30
cols = (ScaleWidth - VScroll1.Width) \ stepX
rows = ScaleHeight \ stepY
' Only update if values have changed
If (cols <> ShowCols) Or (rows <> ShowRows) Then
If (cols > 0) And (rows > 0) Then
ShowCols = cols
ShowRows = rows
Cls
UpdateThumbs
End If
End If
End Sub


' - - - - - - - - -
Sub AddPath(Path As String)
Dim idx As Long, file As Long
' Add \ if missing
If Right$(Path, 1) Like "[!/\]" Then
Path = Path & "\"
End If
' List files
File1.Path = Path
File1.Refresh
' Increase array if needed
If UBound(THM) < (ListCount + File1.ListCount) Then
ReDim Preserve THM(ListCount + File1.ListCount)
End If
' Store filenames (no images yet)
idx = ListCount
For file = 0 To File1.ListCount - 1
THM(idx).Name = Path & File1.List(idx)
idx = idx + 1
Next
ListCount = idx
Caption = "Total: " & CStr(ListCount)
End Sub

Private Sub InitializeForm()
' Initialize form and controls
File1.Pattern = "*.bmp;*.jpg;*.gif"
File1.Move -2000, 0, 1000, 6000
Picture1.BorderStyle = vbBSNone
Picture1.Move 0, 0, 1200, 1200 ' Thumbnail size
Picture1.AutoRedraw = True
Picture1.BackColor = &HEEEEEE
Picture1.Line (0, 0)-Step(Picture1.ScaleWidth, Picture1.ScaleHeight), &HCCCCCC, B
Picture1.Line (-15, -15)-Step(Picture1.ScaleWidth, Picture1.ScaleHeight), &HCCCCCC, B
Picture1.Visible = False
Picture1.ScaleMode = vbPixels
Set Dummy = Picture1.Image
VScroll1.Move ScaleWidth - 240, 0, 240, ScaleHeight
VScroll1.Min = 0
VScroll1.Max = 1
VScroll1.SmallChange = 1
Me.BackColor = vbWhite
' Start with some space in the array
ReDim THM(0 To 100)
End Sub

Private Sub UpdateThumbs()
Dim idx&, X&, Y As Long
Dim stepX As Long, stepY As Long
Dim ready As Boolean
' Draw thumbs to form
stepX = Picture1.Width + 30
stepY = Picture1.Height + 30
idx = TopIndex
For Y = 0 To ShowRows - 1
ready = True
For X = 0 To ShowCols - 1
If idx < ListCount Then
If THM(idx).Image Is Nothing Then
' If not loaded yet, show dummy and clear ready
PaintPicture Dummy, X * stepX + 15, Y * stepY + 15
ready = False
Else
' Image is stored in the array
PaintPicture THM(idx).Image, X * stepX + 15, Y * stepY + 15
End If
Else
' When list ends in the middle of a row, draw the background
Line (X * stepX + 15, Y * stepY + 15)-Step(stepX - 30, stepY - 30), BackColor, BF
End If
idx = idx + 1
Next X
' If loading is needed, load the row and do it over
If Not ready Then
LoadRow idx - ShowCols
idx = idx - ShowCols
Y = Y - 1
End If
Next Y
' Adjust scroll bar physics
VScroll1.Max = (ListCount \ ShowCols) - ShowRows + 1
If VScroll1.Max < 1 Then
VScroll1.Max = 0
VScroll1.LargeChange = 1
Else
If ShowRows > 1 Then
VScroll1.LargeChange = ShowRows - 1
Else
VScroll1.LargeChange = 1
End If
End If
End Sub

Sub LoadRow(ByVal StartIndex As Long)
Dim EndIndex As Long
' Calculate array indexes
EndIndex = StartIndex + ShowCols
If EndIndex > ListCount Then
EndIndex = ListCount
End If
' Load next row
While StartIndex < EndIndex
BuildThumb StartIndex
StartIndex = StartIndex + 1
Wend
End Sub

Sub BuildThumb(Index As Long)
Dim pic As StdPicture
Dim asp As Single, siz As Single
' Load file
Set pic = LoadPicture(THM(Index).Name)
' Calculate aspect
asp = pic.Height / pic.Width
With Picture1
' Start fresh...
Set .Picture = Nothing
If asp >= 1 Then
' Image is tall
siz = .ScaleWidth / asp
pic.Render .hDC, (.ScaleWidth - siz) / 2, .ScaleHeight, siz, -.ScaleHeight, 0, 0, pic.Width, pic.Height, 0
Else
' Image is wide
siz = .ScaleHeight * asp
pic.Render .hDC, 0, .ScaleHeight - (.ScaleHeight - siz) / 2, .ScaleWidth, -siz, 0, 0, pic.Width, pic.Height, 0
End If
End With
' Store thumbnail
Set THM(Index).Image = Picture1.Image
End Sub



From: Nobody on
"Larry Serflaten" <serflaten(a)usinternet.com> wrote in message
news:e8XuQtXZKHA.2188(a)TK2MSFTNGP04.phx.gbl...

Off topic: Please check your system time and time zone. It seems to be one
hour off.