BMP文件右旋90度[c语言]
#include#include #include typedef unsigned short WORD;typedef unsigned int DWORD;typedef unsigned int LONG;#pragma pack(2)typedef struct tagBITMAPFILEHEADER{ WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits;} BITMAPFILEHEADER;#pragma pack()typedef struct tagBITMAPINFOHEADER{ DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant;} BITMAPINFOHEADER;/* fname- 输入文件名称 foname-输出文件名 */void cw90(char *fname,char *foname) { BITMAPFILEHEADER fileHeader; BITMAPINFOHEADER infoHeader; unsigned char palette[8]; FILE *f = fopen(fname,"rb"); if(f == NULL) { printf("Can not find file %s/n",fname); return; } fread(&fileHeader,sizeof(BITMAPFILEHEADER),1,f); fread(&infoHeader,sizeof(BITMAPINFOHEADER),1,f); fread(palette,sizeof(unsigned char),8,f); unsigned char *data = (unsigned char*)malloc(infoHeader.biSizeImage); fread(data,sizeof(unsigned char),infoHeader.biSizeImage,f); FILE *of = fopen(foname,"wb"); BITMAPFILEHEADER oFileHeader; BITMAPINFOHEADER oInfoHeader; int lineSize = ( infoHeader.biHeight + 31) / 32 * 4; int imageSize = lineSize * infoHeader.biWidth; // //////////////////////// oFileHeader.bfType = 19778; oFileHeader.bfSize = 62 + imageSize; oFileHeader.bfReserved1 = 0; oFileHeader.bfReserved2 = 0; oFileHeader.bfOffBits = 62; // //////////////////////// oInfoHeader.biSize = 40; oInfoHeader.biWidth = infoHeader.biHeight; oInfoHeader.biHeight = infoHeader.biWidth; oInfoHeader.biPlanes = 1; oInfoHeader.biBitCount = 1; oInfoHeader.biCompression = 0; oInfoHeader.biSizeImage = imageSize; oInfoHeader.biXPelsPerMeter = 0; oInfoHeader.biYPelsPerMeter = 0; oInfoHeader.biClrUsed = 0; oInfoHeader.biClrImportant = 0; // //////////////////////// fwrite( &oFileHeader , sizeof(BITMAPFILEHEADER) , 1 , of ); fwrite( &oInfoHeader , sizeof(BITMAPINFOHEADER) , 1 , of ); fwrite( palette , 1 , 8 , of ); unsigned char *first = (unsigned char*)malloc(infoHeader.biHeight * oInfoHeader.biHeight); unsigned char *second = (unsigned char*)malloc(infoHeader.biHeight * oInfoHeader.biHeight); int myline = oInfoHeader.biSizeImage / oInfoHeader.biHeight; unsigned char *third = (unsigned char*)malloc(myline * 8 * oInfoHeader.biHeight); unsigned char *forth = (unsigned char*)malloc(myline * oInfoHeader.biHeight); unsigned char *img = (unsigned char*)malloc(oInfoHeader.biSizeImage); // first step int i,j,k,t = -1; int temp = infoHeader.biSizeImage / infoHeader.biHeight; for(i = 0; i < infoHeader.biHeight; i++) { for(j = 0; j < temp; j++) { for(k = 0; k < 8; k++) { if(j*8 + k < oInfoHeader.biHeight) { first[++t] = data[i * temp + j] >> (8-1-k) & 1; } } } } // second step // rotate t = -1; for(i = 0; i < oInfoHeader.biHeight; i++) { for(j = 0; j < infoHeader.biHeight; j++) { second[++t] = first[oInfoHeader.biHeight*j + oInfoHeader.biHeight - i - 1]; } } // step three // fill with 0's t = -1; for(i = 0; i < oInfoHeader.biHeight; i++) { for(j = 0; j < infoHeader.biHeight; j++) { third[++t] = second[i*infoHeader.biHeight + j]; } for(k = infoHeader.biHeight; k < myline * 8; k++) { third[++t] = 0; } } // step four // transfer int u = -1; int m = -1; for(i = 0; i < oInfoHeader.biHeight; i++) { for(j = 0; j < myline * 8; j++) { int sum = 0; for(k = 0; k < 8; k++) { sum += pow(2,8-k-1)*third[++m%t]; } forth[++u] = sum; } } fwrite( forth , 1 , myline * oInfoHeader.biHeight , of ); free(img); free(data); fclose(f); fclose(of); }int main() { cw90("original.bmp","ttt.bmp"); system("pause"); return 0;}
Before:
after:
>更多相关文章
- 09-29如何通过wrap malloc定位C/C++程序的内存泄漏
- 02-25打车软件大战升级,补贴还能维持多久?
- 12-23BMP文件右旋90度[c语言]
- 12-23寻找直方图中面积最大的矩形(C语言版)
- 12-23[ndk,2]ndk开发案例和错误处理
- 12-23[ndk,1]ndk开发,C语言入门讲解
- 12-23C语言连续存储实现队列机制
- 12-23Objective-c 数据类型
首页推荐
佛山市东联科技有限公司一直秉承“一切以用户价值为依归
- 01-11全球最受赞誉公司揭晓:苹果连续九年第一
- 12-09罗伯特·莫里斯:让黑客真正变黑
- 12-09谁闯入了中国网络?揭秘美国绝密黑客小组TA
- 12-09警示:iOS6 惊现“闪退”BUG
- 11-18LG新能源宣布与Bear Robotics达成合作,成为
- 11-18机构:三季度全球个人智能音频设备市场强势
- 11-18闲鱼:注册用户过6亿 AI技术已应用于闲置交
- 11-18美柚、宝宝树回应“涉黄短信骚扰”:未发现
- 11-01京东七鲜与前置仓完成融合
相关文章
24小时热门资讯
24小时回复排行
热门推荐
最新资讯
操作系统
黑客防御
Copyright © 2007 - 2024 Vm888.Com. All Rights Reserved
粤公网安备 44060402001498号 粤ICP备19097316号 请遵循相关法律法规
');})();