要用CCS看bmp的信息的,什么大小,像素
这有一个程序,但不知为何无限循环
#include"stdioh"
#include"stdlibh"
typedefcharElemType;
structImgInfo
{unsignedshortImgBitType;//图像位数(色深xbit)
unsignedshortBmpHeight;//图像高度
unsignedshortBmpWidth;//图像宽度
unsignedshortBmpDataPos;//图像数据的起始位置
unsignedlongBmpSize;//图像数据大小
unsignedlong;//图像是否压缩
};
voidGetBmpInfo(FILEfpBmp,structImgInfoImgInfo1)//获取bmp信息,返回图像数据所含字节数OK
{
fseek(fpBmp,0,0);//读取图像数据的起始位置
fread(&ImgInfo1->BmpDataPos,2,1,fpBmp);
getchar();
}
voidReadImgData(FILEfpBmp,structImgInfoImgInfo1,charBmpData)//将bmp图像数据读入BmpData中
{
fseek(fpBmp,ImgInfo1->BmpDataPos,0);//文件指针移动到图像数据起始位置
fread(BmpData,ImgInfo1->BmpSize,1,fpBmp);
}
voidCnvt24bit()
{
FILEfpBmp;//文件指针
structImgInfoImgInfo1;//储存图像信息
charBmpData;//储存图像数据
fpBmp=fopen("C:/ti/examples/sim62xx/xdais/firtest/xiaotubmp","rb");if(fpBmp==NULL){printf("Erropenfile");getchar();}//打开bmp文件
GetBmpInfo(fpBmp,&ImgInfo1);//获bmp信息
BmpData=(char)malloc(ImgInfo1BmpSize);if(BmpData==NULL){printf("ErrMalloc");getchar();}//注意要强制转换类型
ReadImgData(fpBmp,&ImgInfo1,BmpData);//读取BMP图像数据
fclose(fpBmp);
getchar();
}
voidmain()
{
Cnvt24bit();
}
bmp转成jpg的方法,支持批处理:
步骤1,电脑上下载工具软件后安装打开,选择左边最上面的格式转换功能,然后点击添加文件蓝色按钮,将需要转换格式的bmp添加到软件中,批量添加批量转化更省事。
步骤2,添加完文件后进行设置,右边格式转换下拉框选择“bmp”格式,然后在上面设置转换后的输出目录(保存到哪个文件夹,也可以不设置采用软件默认位置)。
步骤3,设置完成后点击右上角开始转换按钮,启动格式批量转换。稍等片刻完成格式转换后,软件会自动打开保存的文件夹。
步骤4,通过案例可以看到,所有的bmp全部转换成了jpg格式。
可以使用C语言标准函数库中的fopen、fseek、fclose等系列函数来打开bmp位图文件,以及进行相应的处理,下面是一个demo,仅供参考。以下代码在vc60中编译通过。
#include <stdioh>#include <stdlibh>
#define BITMAPFILEHEADERLENGTH 14 // The bmp FileHeader length is 14
#define BM 19778 // The ASCII code for BM
/ Test the file is bmp file or not /
void bmpFileTest(FILE fpbmp);
/ To get the OffSet of header to data part /
void bmpHeaderPartLength(FILE fpbmp);
/ To get the width and height of the bmp file /
void BmpWidthHeight(FILE fpbmp);
//get r,g,b data
void bmpDataPart(FILE fpbmp);
// output data to corresponding txt file
void bmpoutput(FILE fpout);
unsigned int OffSet = 0; // OffSet from Header part to Data Part
long width ; // The Width of the Data Part
long height ; // The Height of the Data Part
unsigned char r[2000][2000],output_r[2000][2000];
unsigned char g[2000][2000],output_g[2000][2000];
unsigned char b[2000][2000],output_b[2000][2000];
int main(int argc, char argv[])
{
/ Open bmp file /
unsigned char fp_temp;
FILE fpbmp;
FILE fpout;
fpbmp= fopen("1bmp", "rb");
if (fpbmp == NULL)
{
printf("Open bmp failed!!!\n");
return 1;
}
fpout= fopen("outbmp", "wb+");
if (fpout == NULL)
{
printf("Open outbmp failed!!!\n");
return 1;
}
bmpFileTest(fpbmp); //Test the file is bmp file or not
bmpHeaderPartLength(fpbmp); //Get the length of Header Part
BmpWidthHeight(fpbmp); //Get the width and width of the Data Part
//
fseek(fpbmp, 0L, SEEK_SET);
fseek(fpout, 0L, SEEK_SET);
fp_temp=(unsigned char )malloc(OffSet);
fread(fp_temp, 1, OffSet, fpbmp);
fwrite(fp_temp,1,OffSet,fpout);
bmpDataPart(fpbmp); //Reserve the data to file
/
如果您想对进行处理,请您再这里插入处理函数!!!!!!!!!!!!!!!!!!
/
bmpoutput(fpout);
fclose(fpbmp);
fclose(fpout);
return 0;
}
void bmpoutput(FILE fpout)
{
int i, j=0;
int stride;
unsigned char pixout=NULL;
stride=(24width+31)/8;
stride=stride/44;
pixout=(unsigned char )malloc(stride);
fseek(fpout, OffSet, SEEK_SET);
for(j=0;j<height;j++)
{
for(i=0;i<width;i++)
{
pixout[i3+2]=output_r[height-1-j][i];
pixout[i3+1]=output_g[height-1-j][i];
pixout[i3] =output_b[height-1-j][i];
}
fwrite(pixout, 1, stride, fpout);
}
}
void bmpDataPart(FILE fpbmp)
{
int i, j=0;
int stride;
unsigned char pix=NULL;
FILE fpr;
FILE fpg;
FILE fpb;
if((fpr=fopen("bmprtxt","w+")) == NULL)
{
printf("Failed to construct file bmprtxt!!!");
exit(1);
}
if((fpg=fopen("bmpgtxt","w+")) == NULL)
{
printf("Failed to construct file bmpgtxt!!!");
exit(1);
}
if((fpb=fopen("bmpbtxt","w+")) == NULL)
{
printf("Failed to construct file bmpbtxt!!!");
exit(1);
}
fseek(fpbmp, OffSet, SEEK_SET);
stride=(24width+31)/8;
stride=stride/44;
pix=(unsigned char )malloc(stride);
for(j=0;j<height;j++)
{
fread(pix, 1, stride, fpbmp);
for(i=0;i<width;i++)
{
r[height-1-j][i] =pix[i3+2];
g[height-1-j][i] =pix[i3+1];
b[height-1-j][i] =pix[i3];
output_r[height-1-j][i] =pix[i3+2];
output_g[height-1-j][i] =pix[i3+1];
output_b[height-1-j][i] =pix[i3];
}
}
for(i =0; i < height; i++)
{
for(j = 0; j < width-1; j++)
{
fprintf(fpb,"%4d",b[i][j]);
fprintf(fpg,"%4d",g[i][j]);
fprintf(fpr,"%4d",r[i][j]);
}
fprintf(fpb,"%4d\n",b[i][j]);
fprintf(fpg,"%4d\n",g[i][j]);
fprintf(fpr,"%4d\n",r[i][j]);
}
fclose(fpr);
fclose(fpg);
fclose(fpb);
}
void bmpFileTest(FILE fpbmp)
{
unsigned short bfType = 0;
fseek(fpbmp, 0L, SEEK_SET);//seek_set 起始位置
fread(&bfType, sizeof(char), 2, fpbmp);
if (BM != bfType)
{
printf("This file is not bmp file!!!\n");
exit(1);
}
}
/ To get the OffSet of header to data part /
void bmpHeaderPartLength(FILE fpbmp)
{
fseek(fpbmp, 10L, SEEK_SET);
fread(&OffSet, sizeof(char), 4, fpbmp);
printf("The Header Part is of length %d\n", OffSet);
}
/ To get the width and height of the bmp file /
void BmpWidthHeight(FILE fpbmp)
{
fseek(fpbmp, 18L, SEEK_SET);
fread(&width, sizeof(char), 4, fpbmp);
fseek(fpbmp, 22L, SEEK_SET);
fread(&height, sizeof(char), 4, fpbmp);
printf("The Width of the bmp file is %ld\n", width);
printf("The Height of the bmp file is %ld\n", height);
}
以上就是关于有谁用DSP做过数字图像处理吗图像咋读取_基于dsp的图像处理全部的内容,包括:有谁用DSP做过数字图像处理吗图像咋读取_基于dsp的图像处理、怎样把bmp图片转换成jpg、用c语言读取24位位图bmp文件等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)