test

据说这个blog网站很专业,那就在这里也建立一个blog备份吧...

TEST

06-08

#include rn#include rn#pragma pack(2)rnrn/*定义WORD为两个字节的类型*/rntypedef unsigned short WORD;rn/*定义DWORD为e四个字节的类型*/rntypedef unsigned long DWORD;rnrn/*位图文件头*/rntypedef struct BMP_FILE_HEADERrnrn WORD bType; /* 文件标识符 */rn DWORD bSize; /* 文件的大小 */rn WORD bReserved1; /* 保留值,必须设置为0 */ rn WORD bReserved2; /* 保留值,必须设置为0 */rn DWORD bOffset; /* 文件头的最后到图像数据位开始的偏移量 */rn BMPFILEHEADER;rnrn/*位图信息头*/rntypedef struct BMP_INFOrnrn DWORD bInfoSize; /* 信息头的大小 */rn DWORD bWidth; /* 图像的宽度 */rn DWORD bHeight; /* 图像的高度 */rn WORD bPlanes; /* 图像的位面数 */rn WORD bBitCount; /* 每个像素的位数 */rn DWORD bCompression; /* 压缩类型 */rn DWORD bmpImageSize; /* 图像的大小,以字节为单位 */rn DWORD bXPelsPerMeter; /* 水平分辨率 */rn DWORD bYPelsPerMeter; /* 垂直分辨率 */rn DWORD bClrUsed; /* 使用的色彩数 */rn DWORD bClrImportant; /* 重要的颜色数 */rn BMPINF;rnrn/*彩色表*/rntypedef struct RGB_QUAD rnrn WORD rgbBlue; /* 蓝色强度 */rn WORD rgbGreen; /* 绿色强度 */rn WORD rgbRed; /* 红色强度 */rn WORD rgbReversed; /* 保留值 */rn RGBQUAD;rnrnint main()rnrn long i=0;rn WORD array[1024]=0xff;rn FILE *fp;rn BMPFILEHEADER fileHeader;rn BMPINF infoHeader;rn long offset, bmpImageSize, width, height, bytesPerPixel, size, bitCount;rn WORD c;rn rn if((fp = fopen("image1.bmp", "rb")) == NULL)rn rn printf("Cann't open the file!\n");rn exit(0);rn rnrn fseek(fp, 0, 0);rn fread(&fileHeader, sizeof(fileHeader), 1, fp);rn fread(&infoHeader, sizeof(infoHeader), 1, fp);rnrn //计算并输出位图数据的偏移量,图像的大小,宽度和高度,每个像素点所占的字节rn size = fileHeader.bSize;rn offset = fileHeader.bOffset;rn bmpImageSize = infoHeader.bmpImageSize;rn width = infoHeader.bWidth;rn height = infoHeader.bHeight;rn bitCount = infoHeader.bBitCount;rn bytesPerPixel = infoHeader.bBitCount / 8;rn rn printf("%d %d %d %d %d %d\n", size, offset, bmpImageSize, width, height, bitCount, bytesPerPixel);rnrn //输出每个像素点所占字节中的内容rn c = fgetc(fp);rn while (!feof(fp))rn rn i++;rn if(i>8)rn array[i-9]=c;rn rn printf("%x ", c);rn c = fgetc(fp);rn rn printf("\n");rn fclose(fp);rn if((fp=fopen("dio.txt","wb"))==NULL)rn printf("Cann't open the file!\n");rn exit(0);rn rn i=0;rn while(i!=1024)rn fprintf(fp,"0x%X,",array[i]);rn i++;rn rn fclose(fp);rn return 0;rn 论坛

没有更多推荐了,返回首页