# Importing an RGBA image from raw binary data?

Problem: I have printed some binary data from gdb which I'd like to inspect as an image. I am able to do this with gimp if I parse the data as an RGBA raw image with width 251 and height 261. However, I'd like to use Wolfram to do this programatically.

I have tried

Import["/path/to/my/raw/image.bin", {"RawBitMap",
"Summary"}, ImageSize -> 251]


which almost works. The issue is that it parses as an RGB file (without an alpha channel), and so the image is totally corrupted.

Question: Is this possible in Wolfram?

• It's definitely possible, perhaps using BinaryReadList. It's hard to be more specific without an example file. Dec 12 '20 at 22:28

This import format seems to be rather inflexible. The documentation, says,

Stores images as RGB or grayscale bitmaps at a resolution of 8 bits per channel.

Thus I would not bother with it.

Import as "Binary", use Partition to put the data into the desired form, then use Image to create the final image. I used something like this for a 150 by 150 image:

data =
ArrayReshape[

• You could use ArrayReshape[data, {150,150,4}] instead of two partitions, and "ColorSpace"->"RGB" can be ColorSpace->"RGB" without the quotes around the option. Dec 13 '20 at 13:55
• You can also use BinaryReadList for the first step to gain some speed. Dec 13 '20 at 16:43