Domanda

Well, I'm a newbie in C++, and it's been two days since I'm looking for examples, explanations, I try different libraries, but I can not do it, so I just ask for help.

I have a picture in .bmp, I know the height and length, I would like to use in my program as a 2D array.

So I found this code, but it does not work. The problem is that my image is 64 bpp, although visually monochrome.

I have read the documentation, but I do not understand, due to my poor skills in C++ and everything related to the low-level programming.

Do you think it is possible to adapt the previous code for bmp image of 64 bits per pixel?

È stato utile?

Soluzione

To my knowledge the bitmap file format does not support 64 bits per component. I'm not aware of any file format that allows such a format (Though id be surprised if one did not exist).

I find it hard to understand why you would need such a VAST range for an image format component.

Edit: Given your comment then yes it is absoloutely possible to adapt that code. Though its worth noting that 0..63 (64 colour levels) is 6-bit. I assume 2 bits are wasted, though.

Its quite simple if it is grayscale and the component is 8bpp. Basically the storage you need is width * height bytes.

char* pBitmap = malloc( bmp.width * bmp.height );

You can then fread the pixels directly into the char buffer above with a single width * height read.

Edit 2:

Ok for 16 bit per component with 4 components you need a struct like this:

struct Pixel16RGBA
{
    unsigned short r;
    unsigned short g;
    unsigned short b;
    unsigned short a;
};

and then you'd allocate as follows:

Pixel16RGBA* pBitmap = (Pixel16RGBA)malloc( bmp.width * bmp.height * 4 * sizeof( unsigned short ) );

You would then fread the whole image in, as before, using the size calcluated in the malloc above.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top