LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert an image in to an array using labwindows cvi

Hi guys!

 

I'm trying to to convert an image in to an array an i have no idea. Please help!!

This is the code:

int rez_op=0;  
    int color[320*240];
    char biti[307200];
    
    
    
            
            rez_op=GetBitmapFromFile ("cam1.jpg", &bmpID11);
            if(rez_op==0)
                SetCtrlBitmap (1, PANEL_PICTURE1, 0, bmpID11);   
            rez_op=GetBitmapFromFile ("cam2.jpg", &bmpID12);
            if(rez_op==0)
                SetCtrlBitmap (1, PANEL_PICTURE2, 0, bmpID12);
            
             DiscardBitmap (bmpID11);
             DiscardBitmap (bmpID12);
            
            
            
            
            GetBitmapData (bmpID11, NULL, NULL, NULL, NULL, color, biti, NULL);   

 

but the GetBitmapData function didn't work. the color array is null.

0 Kudos
Message 1 of 2
(3,051 Views)

Which are the settingf for your display? As can be seen in the help for Color Table parameter:

 

colorTable integer array Array of RGB color values, or NULL if pixelDepth is greater than 8.

If pixelDepth is 8 or less, the bits array contains indices into the colorTable array. The number of entries in the colorTable array must equal 2n, where n is the value of the pixelDepth parameter.

If pixelDepth is greater than 8, the colorTable parameter is not used. The bits array contains actual RGB color values rather than indices into the colorTable array.

 

But remember that when you read a bitmap into CVI with GetBitmapFromFile the resulting bitmap matches the display settings.

This is clearly stated in the help for the command, which recitates:

 

Regardless of the original color depth of the image file, the bitmap that GetBitmapFromFile creates matches the color depth of the display screen.

 

So you must use Bits array instead, and retrieve original colors interpreting it as an RGB value with an optional 2 bytes padding in case pixelDepth = 32.

 

Interpreting the RGB value can be a bit tricky, but you may find useful informations and examples in my Color-to-grayscale or -to-monochrome conversion.

 

 

* Edit *

I see now that you are discarding the bitmap before calling GetBitmapData: this is clearly wrong and you should get an error in that function. Try calling GetBitmapData before discarding the bitmap, but consider that what I wrote before is still valid. Also, you should consider adding some error checking to the code: the function returns a meaninful, negative code in case of error.

colorTable integer array Array of RGB color values, or NULL if pixelDepth is greater than 8.

If pixelDepth is 8 or less, the bits array contains indices into the colorTable array. The number of entries in the colorTable array must equal 2n, where n is the value of the pixelDepth parameter.

If pixelDepth is greater than 8, the colorTable parameter is not used. The bits array contains actual RGB color values rather than indices into the colorTable array.


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 2
(3,045 Views)