将 ICO 转换为 BMP
Converting ICO to BMP
我想读取 ICO 文件并将每个图标保存到单独的 BMP 中。
我的代码对 ICO 文件中的第一个图标进行了处理。但是我不知道在哪里设置文件光标(fseek 到哪里)。
这是我用伪代码执行的步骤:
- 读取 ICONDIR = 读取前 6 个字节:
- UInt16 为 'reserved'(始终为 0)
- Uint16 as 'type'(ICO 为 1,CUR 为 0)
- Uint16 as 'count'(图标数量)
- 读取 ICONDIRENTRY = 接下来的 16 个字节
- Uint8 为 'width'
- Uint8 为 'height'
- Uint8 为 'colors'
- Uint16 为 'color planes'
- Uint16 为 'bits per pixel'
- Uint32 为 'size of image'
- Uint32 为 'offset'
- 将文件位置设置为'offset'。
读取 BITMAPINFOHEADER = 接下来的 40 个字节
- Uint32 为 'header size'
- Uint32 为 'width2'
- Uint32 为 'height2'
- Uint16 为 'color planes2'
- Uint16 为 'bits per pixel2'
- Uint32 为 'compression'
- Uint32 为 'image length'
- Uint32 为 'dpi X'
- Uint32 为 'dpi Y'
- Uint32 为 'colors used'
- Uint32 为 'important colors'
- 读取图像的像素点,从offset = 40 + 'offset'我读取了'width' * 'height' * 'bits per pixel' / 8个字节。
我从 ICO 文件中得到了第一个图标。到目前为止,一切都很好。
但是我现在要查找到哪里呢?我试着从我完成的地方开始阅读,但没有成功。
我知道下一个图标的大小是 48x48 字节,所以我想我应该阅读下一个 ICONDIRENTRY,它应该给我 'width' 和 'height' = 48。但我不知道从哪里开始阅读。
我正在 PHP 中编写程序,但是 PHP 遇到此类问题的人通常会说 'use library X' 或 'use ImageMagick',而我只需要了解算法即可。这类程序通常是用C++编写的,所以我标记了这个C++。
ICO文件中的下一个ICONDIRENTRY在哪里(什么偏移量)?
我想读取 ICO 文件并将每个图标保存到单独的 BMP 中。 我的代码对 ICO 文件中的第一个图标进行了处理。但是我不知道在哪里设置文件光标(fseek 到哪里)。
这是我用伪代码执行的步骤:
- 读取 ICONDIR = 读取前 6 个字节:
- UInt16 为 'reserved'(始终为 0)
- Uint16 as 'type'(ICO 为 1,CUR 为 0)
- Uint16 as 'count'(图标数量)
- 读取 ICONDIRENTRY = 接下来的 16 个字节
- Uint8 为 'width'
- Uint8 为 'height'
- Uint8 为 'colors'
- Uint16 为 'color planes'
- Uint16 为 'bits per pixel'
- Uint32 为 'size of image'
- Uint32 为 'offset'
- 将文件位置设置为'offset'。
读取 BITMAPINFOHEADER = 接下来的 40 个字节
- Uint32 为 'header size'
- Uint32 为 'width2'
- Uint32 为 'height2'
- Uint16 为 'color planes2'
- Uint16 为 'bits per pixel2'
- Uint32 为 'compression'
- Uint32 为 'image length'
- Uint32 为 'dpi X'
- Uint32 为 'dpi Y'
- Uint32 为 'colors used'
- Uint32 为 'important colors'
- 读取图像的像素点,从offset = 40 + 'offset'我读取了'width' * 'height' * 'bits per pixel' / 8个字节。 我从 ICO 文件中得到了第一个图标。到目前为止,一切都很好。
但是我现在要查找到哪里呢?我试着从我完成的地方开始阅读,但没有成功。 我知道下一个图标的大小是 48x48 字节,所以我想我应该阅读下一个 ICONDIRENTRY,它应该给我 'width' 和 'height' = 48。但我不知道从哪里开始阅读。
我正在 PHP 中编写程序,但是 PHP 遇到此类问题的人通常会说 'use library X' 或 'use ImageMagick',而我只需要了解算法即可。这类程序通常是用C++编写的,所以我标记了这个C++。
ICO文件中的下一个ICONDIRENTRY在哪里(什么偏移量)?