RGB转BMP
void RGB2BMP(unsigned char* data, int w, int h, std::string name)
{
FILE* fp = fopen(name.c_str(), "wb");
typedef struct
{
uint16 bmptype;
uint bmpsize;
uint16 bmpre1;
uint16 bmpre2;
uint bmpseek;
}bmphead;
typedef struct
{
uint infosize;
uint iw;
uint ih;
uint16 iplanes;
uint16 ibitcount;
uint iCom;
uint iimagesize;
uint ix;
uint iy;
uint icolorindex;
uint icolorimp;
}infohead;
bmphead bmph = { 0 };
bmph.bmpsize = w * h * 4;
bmph.bmptype = (uint16)0x4d42;
bmph.bmpre1 = 0;
bmph.bmpre2 = 0;
bmph.bmpseek = sizeof(bmphead) + sizeof(infohead) - 2;
char* tmp = (char*)&bmph;
fwrite(tmp, 2, 1, fp);
tmp += 4;
fwrite(tmp, sizeof(bmphead) - 4, 1, fp);
infohead ih = { 0 };
ih.ibitcount = 32;
ih.icolorimp = 0;
ih.icolorindex = 0;
ih.iCom = 0;
ih.iimagesize = 54 + bmph.bmpsize;
ih.infosize = sizeof(infohead);
ih.iplanes = 1;
ih.iw = w;
ih.ih = -h;
ih.ix = 2835;
ih.iy = 2835;
fwrite(&ih, sizeof(infohead), 1, fp);
fwrite(data, bmph.bmpsize, 1, fp);
fclose(fp);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51