NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
devil3ro
Posts: 1
0 Kudos

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.

Trusted Enthusiast
RobertoBozzolo
Posts: 4,532
0 Kudos

Rif.: How to convert an image in to an array using labwindows cvi

[ Edited ]

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.



Using LW/CVI from 3.1 on.

My contributions to the Developer Zone Community
________________________________________
If I have helped you, why not giving a kudos?
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page