|
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef unsigned char BYTE;
typedef unsigned long DWORD;
typedef unsigned short WORD;
#include
typedef struct {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BMPFILEHEADER_T;
struct BMPFILEHEADER_S{
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
};
typedef struct{
DWORD biSize;
DWORD biWidth;
DWORD biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
DWORD biXPelsPerMeter;
DWORD biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BMPINFOHEADER_T;
unsigned char array[8]={0,0,0,0,0xff,0xff,0xff,0};
void Snapshot( BYTE * pData, char * filename )
{
int width=320;
int height=240;
int size = width*height/8;
BMPFILEHEADER_T bfh;
bfh.bfType = 0x4d42;
bfh.bfSize = size + sizeof( BMPFILEHEADER_T ) + sizeof( BMPINFOHEADER_T )+8;
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = bfh.bfSize - size;
BMPINFOHEADER_T bih;
bih.biSize = sizeof(BMPINFOHEADER_T);
bih.biWidth = width;
bih.biHeight = height;
bih.biPlanes = 1;
bih.biBitCount =1;
bih.biCompression = 0; /*******************/
bih.biSizeImage = size;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;
FILE * fp = fopen( filename,"wb");
if( !fp ) return;
fwrite( &bfh, 1, sizeof(BMPFILEHEADER_T), fp);
fwrite( &bih, 1, sizeof(BMPINFOHEADER_T), fp);
fwrite( array, 1, 8,fp);
fwrite( pData, 1, size, fp );
fclose( fp );
}
void main()
{
unsigned char pRGB[320*240/8];
FILE * fpf = fopen("keyima.bin","rb");
if (!fpf) return;
fread(pRGB,1,9600,fpf);
Snapshot((BYTE* )pRGB,"C:\\test.bmp" );
}
这是我的程序
请大家看看
现在就想在程序里实现无损压缩
请大家帮帮吗?帮实现一下
谢谢拉谢谢拉
|
|