第2篇 基于C/C++实现RAW格式图像读取和写出

本文介绍了一段C++代码,该代码用于读取和写入raw格式的图像文件。通过fopen函数打开文件,使用fread读取图像数据到Ipp16u类型的数组中,再使用fwrite将数据写入新的raw文件。此过程展示了基本的文件操作和内存管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码:
#include <iostream>
#include "ipp.h"
#include <stdio.h>
using namespace std;

#define  width  512/* Image width  */
#define  height  512 /* Image height */

int main(void)
{
//fopen读取image
FILE *fpsrc = NULL;  //读入文件指针
Ipp16u *src = new Ipp16u[width*height];  //读入
if ((fpsrc = fopen("src.raw", "rb")) == NULL)
{
	printf("can not open the raw image");
	return 0;
}
else
{
	printf("IMAGE read OK\n");
}
fread(src, sizeof(Ipp16u), width*height, fpsrc);
fclose(fpsrc);

//fwrite写出数据
FILE *fpdst = NULL;  //写出文件指针
Ipp16u *dst = new Ipp16u[width*height];  //写出
fpdst = fopen("dst.raw", "wb");
if (!fpdst)
{
	return 1;
}
fwrite(dst, sizeof(Ipp16u), width * height, fpdst);
fclose(fpdst);


return 0;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值