LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using image data read out from a file

Hi,

 

Having used the GetBitmapFromFileEx(), GetBitmapInfoEx() to acquire the necessary image data (most of them is the .png format), then using the FileToArray() to put the image data in my own binary file, e.g., "mypicture.dat". My idea is that whenever need to use the image, I can read out it from mypicture.dat and then display it on a pcture control.  But when loading the image data to the memory, I have no idea to map the image data buffer to an image resource, which can let to acquire a bitmap ID.  Because from the  cvi's image processing function lists, it seems that must through such as  the GetBitmapFromFileEx(), GetBitmapFromFile() to acquire the image data buffer and the bitmap ID, then using SetCtrlBitmap() to diplay it. Is there any way to resolve the problem? Thanks.

 

 

David 

0 Kudos
Message 1 of 6
(3,901 Views)

I don't exactly understand why you are doing such thing, An image file holds several informations in it which you must store elsewhere to be able to rebuild the image. As an example, consider this project I made some times ago that treats .BMP images (the easiest file format as it doesn't involve any data compression).

Saving image in another format and reloading it involves treating all these informations to and from disk, but these operations are very well performed by image processing functions native in CVI. Your effort seems quite close to reinventing the wheel!



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,894 Views)

Hi Roberto,

 

In deed, I just want to collect the image content into my own data file (it can regard as a database), the related data of the image such as colortable, alpha chennel and so on are all be kept in a file. When my application window need to show an image, just loading the image from my own file, instead of searching a directory then using GetBitmapFromFile() and so on to acquire some parameters such as bitmap ID. The problem is that  I have got the image content and load it into the memory, how to display it directly? Thanks.

 

 

 

David   

0 Kudos
Message 3 of 6
(3,883 Views)

David,

I can see two scenarios.

 

1. Image data are kept in a file separated from other data (i.e. the file holds only the image). In this case, simply make a copy of your png image file or rename it to the name you want and pass it to GetBitmapFromFile.

 

2. The image is saved in your data file together with other data. In this case in my opinion the easiest and fastest thing  you can do is to extract raw bynary image content from the data file and store in a temporary file from which to read again with GetBitmapFromFile.

 

Please remember that normally image files store informations in some compressed way (this is true for png and jpg files, not for bmp but you are not using them) so extracting informations from this files requires some additional work that has already been done from NI.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(3,876 Views)

Roberto,

 

In fact, I am now using the second way of what you have mentioned. Before displaying the image, I have to load the imag content then put it into a tempeorary image file which use the image's original file format firstly, then using the GetBitmapFromFile()  and so on to reacquire the related data of the image, then display it. I think this way  is so tortuous and no efficiency.

 

 

David

0 Kudos
Message 5 of 6
(3,873 Views)

Well, to read and write raw data file informations from a PNG image you must adhere to this standard. As a source of informations you may take a look to this Wikipedia page and to the links in this page from the PNG Home site.

So the problem is: does your application worth the effort to study this documentation?

 

Edit: FYI part of this job has been already made in CVI by Guillaume Dargaud for his ReadSavePNG instrument driver. It's been a long time since I have used this instrument, as I/O operations on PNG files have been integrated into CVI since release 8 and support for JPEG files in release 7 or so. Nevertheless I saw functions in that instrument for accessing raw data in a PNG file so you may find them useful for your needs.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(3,869 Views)