c / C ++中以下代码的等价物是什么?
ref BITMAPFILEHEADER bmfh = ref buffer[offset]; //Where buffer is a byte[] array
答案 0 :(得分:1)
如果您#include <windows.h>
已经有BITMAPFILEHEADER
struct。
PBITMAPFILEHEADER bmfh_ptr = (PBITMAPFILEHEADER)(buffer + offset);
// where buffer is a char[] array.
答案 1 :(得分:1)
可以找到一个24位BMP读写器的操作系统不可知的C ++实现:http://code.google.com/p/bitmap/source/browse/trunk/bitmap_image.hpp
以下是标题和信息块的结构定义:
struct bitmap_file_header
{
unsigned short type;
unsigned int size;
unsigned short reserved1;
unsigned short reserved2;
unsigned int off_bits;
unsigned int struct_size()
{
return sizeof(type) +
sizeof(size) +
sizeof(reserved1) +
sizeof(reserved2) +
sizeof(off_bits);
}
};
struct bitmap_information_header
{
unsigned int size;
unsigned int width;
unsigned int height;
unsigned short planes;
unsigned short bit_count;
unsigned int compression;
unsigned int size_image;
unsigned int x_pels_per_meter;
unsigned int y_pels_per_meter;
unsigned int clr_used;
unsigned int clr_important;
unsigned int struct_size()
{
return sizeof(size) +
sizeof(width) +
sizeof(height) +
sizeof(planes) +
sizeof(bit_count) +
sizeof(compression) +
sizeof(size_image) +
sizeof(x_pels_per_meter) +
sizeof(y_pels_per_meter) +
sizeof(clr_used) +
sizeof(clr_important);
}
};
答案 2 :(得分:1)
字面翻译:
BITMAPFILEHEADER *bmfh = &(buffer[offset]);
在c ++中可能更自然:
PBITMAPFILEHEADER bmfh = (PBITMAPFILEHEADER)(buffer+offset);
但要注意,要使这两个工作正常,缓冲区最好被定义为字符类型。
请注意,PBITMAPFILEHEADER被定义为BITMAPFILEHEADER *,就像Windows命名一样。