转储原始图像数据

时间:2015-06-20 09:18:18

标签: c++ windows image raw-data

我有一个以原始字节形式存储在存储器中的图像,即我有char*指向图像数据的存储位置。现在,我需要以某种方式验证图像数据是否合法。

我目前尝试的是简单地将字节转储到文件中。我试过转储到3种类型的文件,但没有运气:

std::ofstream ofs;
ofs.open("Image.raw", std::ofstream::out);
ofs.write((char*)imgData, imageInfo.imageLen);
ofs.close();
// Have also tried "Image.tiff" and "Image.ppm"

有没有办法查看内容?简而言之,我在Win平台上编写此代码。几年前,我记得在MAC OS X上做了类似的事情,取得了成功的结果!。

1 个答案:

答案 0 :(得分:1)

You can write it straight out as RGB in binary like you already have - say to a file called image.rgb.

Then use ImageMagick, which is installed on most Linux distros, and available for OSX and Windows to convert it to PNG, JPEG or something more common:

convert -size 300x400 -depth 8 image.rgb result.png

or

convert -size 300x400 -depth 8 image.rgb result.jpg

You will need to tell ImageMagick the dimensions of the image as above because they are obviously not embedded within a raw file like they would be in a JPEG or PNG with a header.

If the filename you choose does not end in .rgb, you will need to prefix it with RGB: like this

convert -size ...   RGB:something.bin   result.png