raw文件 在C语言中用什么打开,C语言实现raw格式图像的读入和存取

[cpp]

/*========================================================================*/

//

// Description:  针对RAW图像的读入和存取

//

// Arguments:

//

// Returns:

//

// Notes:        none

//

// Time:         none

//

// Memory:       none

//

// Example:      none

//

// History:      1. wangyi   2014-4-19 22:46   Verison1.00   create

/*========================================================================*/

#include 

#include 

#include 

#define height  256

#define width   256

typedef unsigned char  BYTE;    // 定义BYTE类型,占1个字节

int main()

{

FILE *fp = NULL;

BYTE B[height][width];

BYTE *ptr;

char path[256];

char outpath[256];

int i,j;

// 输入源路径并打开raw图像文件

printf("Input the raw image path: ");

scanf("%s",path);

if((fp = fopen( path, "rb" )) == NULL)

{

printf("can not open the raw image " );

return;

}

else

{

printf("read OK");

}

// 分配内存并将图像读到二维数组中

ptr = (BYTE*)malloc( width * height * sizeof(BYTE) );

for( i = 0; i 

{

for( j = 0; j 

{

fread( ptr, 1, 1, fp );

B[i][j]= *ptr;  // 把图像输入到2维数组中,变成矩阵型式

printf("%d  ",B[i][j]);

ptr++;

}

}

fclose(fp);

// 这里可以对二维数组中的图像数据进行处理

// 将处理后的图像数据输出至文件

printf("Input the raw_image path for save: ");

scanf("%s",outpath);

if( ( fp = fopen( outpath, "wb" ) ) == NULL )

{

printf("can not create the raw_image : %s\n", outpath );

return;

}

for( i = 0; i 

{

for( j = 0; j 

{

fwrite( &B[i][j], 1 , 1, fp );

}

}

fclose(fp);

}

上述程序实现了读入和存取的功能,中间可以自己加入对图像数据的处理算法,如注释中所述即可。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值