03-02-2010 10:48 AM
Hello All,
I was trying to build a panel to show multiple photos (50) for verification (double click to view whole image in separate window) prior to upload for final storage.
I need to resample / thumbnail to approximately fit the control so that the memory usage does not go through the roof. These images will be from several cameras and as such the image type may change - but starting with jpg would go along way.
This may be as simple as a missed setting on the uir but I was not able to figure it out. I am not opposed to creating temp thumbnails on the hard drive and clean them away later.
Prefer CVI or SDK to ActiveX etc.
Thanks in advance,
Greg
Solved! Go to Solution.
03-02-2010 01:16 PM
One possibility you have, which does not make use of any external piece of software, is to actually use a native picture control to resize your images. The trick is to set the picture control to Size image to control, load the picture and call GetCtrlDisplayBitmap to get the fitted bitmap.
I made up a small exmple that let you choose an image and loads it 48 times into small picture controls: it takes less than 4 seconds to load a 300x300 pixels bitmap andmore or less 9 with a 900x1300 pixels png image.
You do not need to actually save thumbnails to disk, but the sample lets you choose to create files so that you can compare execution time, see the resulting thumbnails on disk and decide what to do in you application.
03-02-2010 03:31 PM
Very Clever.
I will give it a try and report back.
Thanks for the prompt reply.
Greg
03-02-2010 03:52 PM
Worked like a dream. Thanks again.
Greg
03-02-2010 05:15 PM
Just another case of ultimate support from Roberto 😉
Probably SetCtrlBitmap function was there just to show an alternative.
I commented it without destroying the program requirements.
You can also put GetCtrlDisplayBitmap and DiscardBitmap functions inside "if (save)" block.
This may make things quicker if saving is not required.
03-03-2010 02:05 AM
ebalci wrote:Probably SetCtrlBitmap function was there just to show an alternative.
I commented it without destroying the program requirements.
You can also put GetCtrlDisplayBitmap and DiscardBitmap functions inside "if (save)" block.
This may make things quicker if saving is not required.
Well, actually not. SetCtrlBitmap helps reducing memory occupation in the process: on a limited-memory machine, loading several big images can ultimately lead to a Out-of-memory error in DisplayImageFile and in not displaying the image on the panel. Reloading a smaller bitmap in the controls reduces this effect. As an example, on a 1Gb memory machine progressive loading of a 900x650 pixels bmp image generates such error after more or less 40 images loaded. The bigger the image, the fastest this effect will show. Trapping that non-fatal error permits the function to conclude but the images are not loaded to screen.
In that scenario, adding DiscardBitmap has no effect at all, as memory for the image is allocated inside the picture control.
...it seems your development machine is much bigger than mine