03-10-2011 03:38 AM
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.
03-10-2011 05:16 AM - edited 03-10-2011 05:22 AM
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. |