LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I transfer the binary data of an image to a Bitmap?

A certain part of my project consists in retreiving an image from a remote machine, which I am doing over TCP using HTTP GET method. The problem is that once I have retreived all the image bits in a char array, I don't know how to transfer it to a Bitmap. The only method I can think of is to create a file with the binary data, and then use GetBitmapFromFile. Is this the only possible way?

 

P.S. The image is a jpeg, if that's important. 

Message Edited by bodisan on 03-13-2009 09:26 AM
0 Kudos
Message 1 of 5
(3,577 Views)

If you already have the image bits in an array, you can use the NewBitmap function to create a bitmap object. You don't have to write it to a file first.

 

Luis

0 Kudos
Message 2 of 5
(3,564 Views)
I think I used the wrong words... the http server is not sending me the image bits, it sends the binary data of the jpeg. As I understand it, the image bits are not the same with the jpeg data. The image bits are a plain description of each pixel, and the jpeg data contains a header, and the compressed information about the pixels.
0 Kudos
Message 3 of 5
(3,557 Views)

If it is the case that you are transferring actual jpg file bytes, then you should just be able to do something like the following:

 

 

FILE * jpgFile;
jpgFile = fopen("c:\\myfile.jpg", "wb");// write a binary file
fwrite(jpgDataBuf, /*size of the buffer */, /*num elements*/, jpgFile);
fclose(jpgFile);

 

NickB

National Instruments 

0 Kudos
Message 4 of 5
(3,552 Views)

additionally, you may use a library for decoding the jpeg image in memory.

 

the first such library that comes to my mind is libjpeg which has a windows precompiled binary package here. download the package, include the .lib, and .h, read the doc, and do not forget to put the .dll along with your .exe.

i am pretty sure you can find a lot of similar libraries on the web.

0 Kudos
Message 5 of 5
(3,535 Views)