user3047110
user3047110

Reputation:

Create a grayscale image from 16-bit data using C++

I have an array of 16-bit values and I want to create an image (such as BMP) so that I can view it. Does anyone have suggestions of how to do this? Thanks

Upvotes: 0

Views: 1091

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 208033

Say your image is 200px by 100px. Write the 20,000 16-bit vales to a binary file.

At the commandline, run ImageMagick:

magick -depth 16 -size 200x100 gray:yourFile.bin image.png

Or, if you want a JPG

magick ... image.jpg

For a tiny bit more effort, you could write a 16-bit PGM file which would have the benefit that it contains its dimensions and bit depth in a small ASCII header so the conversion in ImageMagick is simpler, and other programs such as GIMP can read it:

magick yourFile.pgm  image.jpg

The header would be:

P5
200 100
65535
... binary data as above ...

See Wikipedia NetPBM article.

Upvotes: 1

Related Questions