(I know there are solutions for this problem and i tried most of them at least, but with no result)
Im making a program where I try load multiple images at once, resize each one and add them in a listview.
When I add them directly to listview, there is an error.
When I add them to imagelist first, there is an error.
When I add them to an image array(i think its called like that)
(e.x. dim img() as image), there is an error.
When I try all the above, but firstly resize them, there is also an error.
When I say "an error", I mean "Out of memory".
Specifically, the error occurs when I try to load the third image as a bitmat, either for changing its dimensions, or for directly adding them to the listview.
[e.x. Dim img as new Bitmap(Image.fromfile(D:\example.png)]
i try to load 893 images with dimensions 8k or 16k and their size varies between 900mb to 2.2GB each.
Code:
Public Sub addicon(imagepath As String, ImageNameNoExtension As String)
'the point where I get the error'
'-----------------------'
Dim bm_source As New Bitmap(Image.FromFile(imagepath))
'--------------------------'
Dim gr_dest As Graphics
If bm_source.Width = bm_source.Height Then
w = 300
h = 300
Else
If bm_source.Width > bm_source.Height Then
Dim fw = bm_source.Width
w = 300
factor = w / fw
h = bm_source.Height * factor
Else
Dim fh = bm_source.Height
h = 300
factor = h / fh
w = bm_source.Width * factor
End If
End If
Dim bm_desk As New Bitmap(bm_source, CInt(w), CInt(h))
bm_desk.SetResolution(10, 10)
ImageList1.Images.Add(ImageNameNoExtension, bm_desk)
ListView1.LargeImageList = ImageList1
ListView1.Items.Add(ImageNameNoExtension, ImageNameNoExtension)
ListView1.Refresh()
End Sub
Any suggestions about the problem or any further questions are appriciated.