#include<iostream>
using namespace std;
void main()
{
#pragma pack(push)
#pragma pack(2)
typedef struct
{
unsigned short bfType;
unsigned long bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned long bfOffBits;
} bmpfileheader;
#pragma pack(pop)
typedef struct
{
unsigned long biSize;
long biWidth;
long biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
} bmpinfoheader;
typedef struct
{
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbReserved;
} RGBQUAD;
bmpfileheader bfheader;
bmpinfoheader biheader;
RGBQUAD rgb;
bfheader.bfType=0x4D42;
bfheader.bfSize=14+40+1024+512*512;
bfheader.bfReserved1=0;
bfheader.bfReserved2=0;
bfheader.bfOffBits=14+40+1024;
biheader.biSize=40;
biheader.biWidth=512;
biheader.biHeight=512;
biheader.biPlanes=1;
biheader.biBitCount=8;
biheader.biCompression=0;
biheader.biSizeImage=512*512;
biheader.biXPelsPerMeter=2834;
biheader.biYPelsPerMeter=2834;
biheader.biClrUsed=256;
biheader.biClrImportant=0;
rgb.rgbReserved=0;
FILE *fp=fopen("lena.raw","rb");
if(fp==0)
cout<<"file open error";
unsigned char bmpdata[512][512];
unsigned char rawdata[512][512];
fread(rawdata,1,512*512,fp);
fclose(fp);
for( int height=0;height<512;height++)
for( int width=0;width<512;width++)
bmpdata[height][width]=rawdata[511-height][width];
FILE *newfp=fopen("lena.bmp","wb");
if(newfp==0)
cout<<"file can't be created";
fwrite(&bfheader,14,1,newfp);
fwrite(&biheader,40,1,newfp);
for(int i=0;i<256;i++)
{
rgb.rgbBlue=rgb.rgbRed=rgb.rgbGreen=i;
fwrite(&rgb,sizeof(RGBQUAD),1,newfp);
}
fwrite(bmpdata,1,512*512,newfp);
fclose(newfp);
cout<<"success"<<endl;
}
没有合适的资源?快使用搜索试试~ 我知道了~
lena的raw格式转换成8位bmp图像C代码.rar
共20个文件
pdb:3个
pch:2个
ilk:2个
1星 需积分: 19 28 下载量 44 浏览量
2017-12-21
20:52:21
上传
评论 1
收藏 1.48MB RAR 举报
温馨提示
lena的raw格式转换成8位bmp图像C代码.rar 包括lena的raw格式,lena的bmp格式图片
资源推荐
资源详情
资源评论
收起资源包目录
lena的raw格式转换成8位bmp图像.rar (20个子文件)
lena的raw格式转换成8位bmp图像
lena.raw 256KB
raw2bmp.dsw 522B
raw2bmp.ncb 41KB
Debug
raw2bmp.ilk 364KB
vc60.pdb 100KB
r2b.obj 38KB
vc60.idb 73KB
r2b.ilk 364KB
raw2bmp.pdb 577KB
raw2bmp.obj 38KB
r2b.pch 1.9MB
raw2bmp.exe 248KB
r2b.pdb 577KB
r2b.exe 248KB
raw2bmp.pch 1.9MB
raw2bmp.cpp 2KB
raw2bmp.opt 48KB
raw2bmp.dsp 3KB
lena.bmp 257KB
raw2bmp.plg 751B
共 20 条
- 1
资源评论
- s2y3g42018-04-03压缩文件损坏了,不能解压缩。。。。。。
Monsant
- 粉丝: 2
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功