Question ImageList is slow

gtardio

New member
Joined
Apr 12, 2011
Messages
4
Programming Experience
3-5
Hi,

I use this line of code to add images to a imagelist, and link it to listview, but it is very very slow. Up to 40 seconds to add 100 images.

Private Sub create()

Dim img As System.Drawing.Image
Dim imagepatha As String

imagepatha = "C:\ImageInput\imag1.tif"
img = New System.Drawing.Bitmap(imagepathA)
ImageList1.Images.Add(img)
img.Dispose()

End Sub


I have also used, with no difference

img = new System.Drawing.Image.FromFile(ImagePathA)

1.- If a do addrange will it help. Can some one post a addrange example

imagelist.images.addrange(¿?)

2.- Would a multithreading help?

3.- Other suggstion?

Thanks,
 
What sizes are the images that you are adding?
 
Hi,

The images are black & white tiff at 300 dpi, so they are small. 10KB to 50KB at depending wheter they have more black pixels or not. This is for a scanning application that loads the original scanned images to a listView

Regards,
 
I tried your code with a 7MB image and loaded it 100 times, it took about 2 seconds, so I don't believe it is your code. It could be your computer being slow about releasing the image, etc. You could use threading, but it would still take the same amount of time to load the images, you would just be able to do other tasks at the same time. I would give the AddRange method a try, I did a quick Google search and a lot of people say it worked for them. How are the images you are loading named? If they are named like "file1.jpg", "file2.jpg", "file3.jpg" then it is easy, otherwise you have to write out every file name.

-Josh
 
Addrange or MultiThreading for imagelist

Thanks for your reply

The project is to scan documents. To scan the paper tray of 50 docs it takes around 15 seconds. To fill the listview it takes me 20 seconds and to my client 40. So it is not operative

1.- I have tried many ways to use imagelist1.Images.Addrange() but cannot find a code that works even with files named named like "file1.jpg", "file2.jpg"
eg
imagelist1.Images.Addrange({file1.jpg, file2.jpg}) does not work

2.- I tried multhreading (code below) so that while iteh user scans the list view can be filling so the user does not wait an extra 40 seconds for every 50 pages of scan. In this example it works but in the original project I get an error on (index out of range) which I guess the message is not correct when accesing objects of the form.

imagelist1.Images.Add(img)

sample code
*********************************

Imports System.Threading

Public Class Form1

Private thread1 As Thread
Dim delegate1 As ThreadStart = New ThreadStart(AddressOf CreateThumb)

'timer to show that it does not stop ticking while running thread1. Have to add a timer 'to the form
Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
timeLabel.Text = DateTime.Now.ToLongTimeString
End Sub

'Sub that adds images to an imagelist for a listview
Private Sub CreateThumb()
Dim img As System.Drawing.Image
Dim x As Integer
Dim ImagePathA As String

labelmessage.text = "adding images"
ImagePathA = "C:\ImagenesInput\imag1.TIF"
For x = 1 To 150
img = System.Drawing.Image.FromFile(ImagePathA)
imagelist1.Images.Add(img)
img.Dispose()
Next
labelmessage.Text = "finished adding images"
End Sub


'Sub that starts scanning when the scan button is clicked
Private Sub Scan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Scan.Click
Scan.Enabled = False
'Do scanning process
thread1 = New Thread(delegate1)
thread1.Start()
Scan.Enabled = True
End Sub



End Class
*************************************************
 
Hi,

I will not use multi threading becasue at the end it is still consumes time.

SO I really need to try the add range method.

The way to add single images is

myimage = New System.Drawing.Bitmap(ImagepathA)
imagelist1.Images.Add(imyimage)


BUT to make the process faster, my last hope is to use the addrange


imagelist.images.addrange()

in this link MSDN link there is this example I cannot manage to make it work

ImageList.ImageCollection.AddRange Method (System.Windows.Forms)


Public Sub AddRange ( _ images As Image() _ )
'Usage Dim instance As ImageList..::.ImageCollection Dim images As Image() instance.AddRange(images)



ANY clues would be highly appreciated,

Thanks
 
Back
Top