LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Display Image directly from jpg data array

Hi there,

from a camera i'm receiving a viewfinder image. I want to display this image
directly on the screen. But i don't know what's the contens of the image
data (jpg compression etc), so the only way i found ist to save the data end
then reload it:

fileHandle = OpenFile("tmp.jpg", VAL_READ_WRITE, VAL_TRUNCATE,VAL_BINARY);
bytes = WriteFile (fileHandle,pVFData, Size);
CloseFile(fileHandle);
// Read bmp
error = GetBitmapFromFile (("tmp.jpg",, &bmp.ID);
error = CanvasDrawBitmap (viewfinder.handle, viewfinder.canvas, bmp.ID,
VAL_ENTIRE_OBJECT, VAL_ENTIRE_OBJECT);
DiscardBitmap(bmp.ID);

But the framerate is about 20 fps, and i think its not good to create a file
20 times per second for hours and hours.

Does anybody have an idea how i can handle the bmp without saving and
reloading it?

I know that the image has a size of 320 x 240 Pixel, but he size of the data
array (pVFData) varies an is someware in the are of 5580 bytes.

My CVI Version is 8.1.0 and i don't have the Vision add on

Thanks for any idea......

Norbert Rieper
Bremerhaven
Germany


0 Kudos
Message 1 of 6
(4,633 Views)
Dear Norbert

Look in the specifications for your camera for the image type it uses
(commonly it's JPEG, TIFF or RAW).

Either way, when you write the data to disk as you do, you should be able
to look at the first couple of bytes to see whether they contain "JFIF"
(for JPEG), "PNG", "BM6" (for BMP) etc. indicating the file type.

Best regards

Philipp Roessler
0 Kudos
Message 2 of 6
(4,580 Views)
Hy Philipp,

i know that the image type is jpeg. What i try to do is to receive the jpeg
from the camera and display it right away. I don't see a function in cvi to
do this. That's why i have to write the jpeg to disk and read it back as a
bmp. I think the problem is that a jgpeg data is compressed and must be
decompressed to display it and as i mentioned before i dont't see a function
in CVI that can handle this :o(

Greetings

Norbert


"Philipp Roessler" <x@no.email> schrieb im Newsbeitrag
news:1182503424823-540356@exchange.ni.com...
> Dear Norbert Look in the specifications for your camera for the image type
> it uses(commonly it's JPEG, TIFF or RAW).Either way, when you write the
> data to disk as you do, you should be ableto look at the first couple of
> bytes to see whether they contain "JFIF"(for JPEG), "PNG", "BM6" (for BMP)
> etc. indicating the file type.Best regardsPhilipp Roessler


0 Kudos
Message 3 of 6
(4,573 Views)

If the image type is JPG, what should i do to display the image data array by canvas??

Thank you for the attention.

 

zhl929

 

0 Kudos
Message 4 of 6
(3,850 Views)

CVI doesn't (as far as I know) have functions to convert bitmap formats in memory. A bit odd, since it can read and write files in various formats.

 

You'll need to use a JPG decompressor such as the Independent JPEG group's library, then you can use NewBitmap() or NewBitmapEx() to convert the decompressed data to a CVI bitmap.

 

 

--
Martin
Certified CVI Developer
0 Kudos
Message 5 of 6
(3,840 Views)

You can use GetBitmapFromFile or GetBitmapFromFileEx to read a JPEG file into an in-memory bitmap. Once the bitmap is in memory, you can display it on the canvas. By the way, once a bitmap is in memory, it no longer has a distinctive format (BMP, TIFF, PNG, JPEG, etc...). It no longer matters how it was loaded or created in the first place.

 

If you then need to save it back to a file, then you need to pick the function that matches the file format that you want to save it as (e.g. SaveBitmapToJPEGFile)

 

Luis

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