Posted 8 September 2017, 12:53 pm EST
I need to display a column of images that are loaded from a database.
I used to do this by writing each image to a file and then using the LoadPicture() method (in the COM version of Spread) to load the cell.
(This apparently made a copy as I was immediately able to reuse the SAME file.)
I tried using a similar method with Spread.Net - reusing the same file for each cell, and using System.Image.LoadFile(). However that tells me that the file is in use (presumably by the first cell) as soon as I try to load the second image. Apparently it does not really 'Load' the image it simply keeps a pointer to the file.
I then tried cloning a second image from the first and Disposing the first image. That failed since the clone apparently also keeps a reference to the file.
I finally got it to work using the following code but I am not sure how large a resource hit I will take if I create (possibly thousands) of bitmaps in memory.
Dim img As Image = Image.FromFile(Path.Combine(LOBPath, FName))
Dim bmp As Bitmap = New Bitmap(img)
sheet.Cells(row, c).Value = bmp
Can anyone suggest how to load a large number of images with the least resource usage. (without any ties to file storage of the images)
My real concern is that a bitmap requires considerably more memory than a jpg file so I was hoping that I could keep the images compressed - expanding them to bitmaps only in those cells that were rendered.
Thanks for any suggestions.