I was trying to generate an image from a list of bytes so I only had to Import
an Image
once as I want to store a Base64Encoded string in a database using the Imported bytes.
I found one solution but not sure why ImportByteArray
is needed when generating an Image
from bytes?
image = Import[
"http://www.wolfram.com/common/framework/img/spikey.en.png", "Image"]
imageBytes =
Import["http://www.wolfram.com/common/framework/img/spikey.en.png",
"Byte"]
imageBinary =
Import["http://www.wolfram.com/common/framework/img/spikey.en.png",
"Binary"]
imageBytes === imageBinary
(*true*)
imageBytes === Normal[BinarySerialize[image]]
(*False*)
To Generate Image
from bytes, one solution is:
decodedImage = Image[ImportByteArray[ByteArray[imageBytes]], "Byte"]
decodedImage === image
(*True*)
Why do you need the ImportByteArray
? You should be able to:
imageData = Image[imageBytes, "Byte"]
(*ERROR Image::imgarray*)
This also does not work:
imageData = Image[ByteArray[imageBytes], "Byte"]