03-01-2011 08:38 AM
Hi to all,
I have CVI 2010.
I created different bitmaps (.bmp) using Paint and saving them with different pixel depths (monocromatic, 16 bit, 24bit color, 8bit).
The file property details (left click in windows, property, details) give the right pixel depth (in bit and in byte).
I wrote a program for reading these files (with GetBitmapFromFile) but, regardless of the file, the function GetBitmapData returns always a pixel depth of 32 bit (4 byte)!
I also created a code to display bitmap data and the values are corrected but the values are the same in the first 3 bytes (the 4th byte is always 0)
This is a problem for my application because I need to read files (bmp or tif) with 16bit pixeldepth and if the program cannot distinguish between 16 bit and RGB (first 3 bytes)
I have no way to convert them in the correct number...
Anyone can help me?
Thanks to all
Here there is my code:
int pixeldepth=0,width=0,height=0;
unsigned char *Bits=NULL;
int x=0,y=0,BitsSize=0,BytePerRow=0;
char PathName[MAX_STRING],txt[9999];
int current_bitmapID=0; // global
// PathName is given by another function
GetBitmapFromFile(PathName,¤t_bitmapID);
GetBitmapInfo(current_bitmapID,NULL,&BitsSize,NULL);
Bits = malloc (BitsSize);
GetBitmapData(current_bitmapID,&BytePerRow,&pixeldepth,&width,&height,NULL,Bits,NULL);
sprintf(txt,"\n\n width=%d height=%d pixeldepth=%d bitsize=%d byte/pixel=%d\n",width,height,pixeldepth,BitsSize,(BitsSize/(width*height)));
SetCtrlVal(panel_main,PANEL_MAIN_TEXTBOX,txt);
sprintf(txt,"\n\n byte per row=%d byte/pixel = %d",BytePerRow,BytePerRow/width);
SetCtrlVal(panel_main,PANEL_MAIN_TEXTBOX,txt);
for(y=height/2; y<height/2+2; y++) {
sprintf(txt,"\ny=%3d |",y);
for(x=0; x<width; x++) {
sprintf(txt1," %3d %3d %3d %3d |",Bits[y*width*4+4*x],Bits[y*width*4+4*x+1],Bits[y*width*4+4*x+2],Bits[y*width*4+4*x+3]);
strcat(txt,txt1);
}
SetCtrlVal(panel_main,PANEL_MAIN_TEXTBOX,txt);
}
For example: if the image is composed by alternating pixels of black and white I suppose a bitmap array of 0 255 0 255 0 255 ....
Instead the program reads 0 0 0 0 255 255 255 0 0 0 0 0 255 255 255 0 .... and pixeldepth is 32 and byte/pixel is 4
03-01-2011 08:47 AM
Hi,
from the help of GetBitmapFromFile:
Regardless of the original color depth of the image file, the bitmap that GetBitmapFromFile creates matches the color depth of the display screen
Wolfgang
03-01-2011 11:02 AM
Wolfgang is right pointing you to that line of the online help.
If you want access original bitmap data as saved in paint or other programs you may find useful my contribution Color-to-grayscale or -to-monochrome conversion which discusses some aspect of inner content of bitmap format and shows how to directly read binary content of a bmp file.
03-07-2011 07:47 AM
Thanks to all.
So the images are read depending on the monitor used.
What a pity.
Thank you Roberto for your Color-to-grayscale or -to-monochrome conversion!
I will study it!
Bye to all