/**
24位深的bmp图片转换为16位深RGB565格式的bmp图片
**/
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef unsigned char uint8;
typedef char int8;
typedef unsigned short uint16; //32bit system
typedef short int16;
typedef unsigned int uint32;//32bit system
typedef int int32;
struct bmp_filehead //14B
{
//2B 'BM'=0x424d;
uint16 bmtype; //'BM',2B
uint32 bmSize; //size,4B
uint32 bmReserved;//0x00,4B
uint32 bmOffBits;//4B,... 54
}head1;
struct bmphead //40B
{
uint32 bmpOffBits;//4B,... 40
uint32 bmp_wide;//4B,wide
uint32 bmp_high;//4B,high
uint16 bmplans;//2B,0 or 1
uint16 bitcount;//2B ,24
uint32 bmpyasuo;//4B,0
uint32 imagesize;//4B,w*h*3
uint32 biXPelsPerMeter;
uint32 biYPelsPerMeter;
uint32 biClrUsed;
uint32 biClrImportant;
}head2;
struct BGR_data //40B
{
uint8 B_data;
uint8 G_data;
uint8 R_data;
}clr_data[1024*768]; //img size must less than 1024*768
bool bmp565_write(unsigned char *image, uint32 width, uint32 height, const char *filename)
{
unsigned char buffer[1024*1024] = {
0};
uint32 file_size;
uint32 data_size;
unsigned int widthAlignBytes;
FILE *fp;
// 文件头
unsigned char header[66] = {
// BITMAPFILEINFO
'B', 'M', // [0-1] bfType:必须是BM字符
0, 0, 0, 0, // [2-5] bfSize:总文件大小
0, 0, 0, 0, // [6-9] brReserved1,bfReserved2:保留
sizeof(header), 0, 0, 0,
24位深的bmp图片转换为16位深RGB565格式的bmp图片源码
最新推荐文章于 2025-04-12 23:39:05 发布