BITMAPINFOHEADER biHeight is twice what I expect
Asked Answered
E

2

6

I'm writing an application in C to parse Windows Icon files (ICO).

When I read in the BITMAPINFOHEADER struct for an existing icon entry, all of the variables within the struct contain values that are expected, except that biHeight, which should contain the height in pixels of the image, is always twice what it should be.

So for example if I have a 64x64 icon, biWidth is 64, but biHeight is 128.

Is this expected behavior? This is my first time dealing with BITMAPINFOHEADER.

I'm mainly operating from the MSDN article on BITMAPINFOHEADER.

Enameling answered 28/4, 2011 at 2:17 Comment(0)
D
8

Yes, this is normal. It is the added height of the "AND" bitmap mask and the "XOR" bitmap mask, so for any normal icon it is simply 2X the icon height. (Those masks aren't used for 32-bit icons anymore; they are a holdover.) Just divide by two.

Dilatory answered 28/4, 2011 at 2:24 Comment(2)
The icon should contain a valid XOR mask, people are not running at 32bpp 100% of the time (Or include images at lower bit depth also)Cathey
See the second paragraph in this Wikipedia section for a somewhat official confirmation of this answer.Mota
C
0

The data type of the height field is uint16 for BITMAPCOREHEADER, int32 for BITMAPINFOHEADER or later.

To calculate value to store when writing the height field:

let heightToStore = height * (rowOrderIsTopDown ? -1 : 1) * (isEmbededInIco ? 2 : 1);

And to calculate actual height when reading the height field

let rowOrderIsTopDown = heightRead < 0;
let height = heightRead * (rowOrderIsTopDown ? -1 : 1) / (isEmbededInIco ? 2 : 1);
Corcovado answered 30/8, 2023 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.