LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Bitmap has always 4 byte of pixel depth calling GetBitmapData

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,&current_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

0 Kudos
Message 1 of 4
(3,775 Views)

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

 

0 Kudos
Message 2 of 4
(3,769 Views)

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.



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 3 of 4
(3,760 Views)

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

 

0 Kudos
Message 4 of 4
(3,706 Views)