# Iconize a compressed image

I want to embed a compressed image in a notebook so that only an icon is visible (and not the whole image).

The following procedure seems to work :

ExampleData[{"TestImage", "Lena"}] // ExportString[#, "JPG"] & //
Iconize[#, "lena 00 compressed"] &


One can copy-paste the icon above in the following code and evaluate it.
Then the image is retrieved.

ImportString["paste the icon here","JPG"]


The problem

If I quit, reopen and evaluate only the cell with ImportString[..., it doesn't work anymore.

Any solution/workaround for this problem ?

Notes :

• My real aim is to embed a video as a list of 200 compressed images under a simple icon. The compression is necessary because of this problem. Morever, I need to retrieve a list of independently compressed images in order to Manipulate[] them with good reactivity (forward and backward. The decompression, which is quick, is made on the fly)

• I have tried without success to replace Iconize[...] by some code with Interpretation[...].

Mathematica 11.3 Windows 7 (64bits)

Update

@andre mentions that an alternative to the two step procedures in my original answer is to convert the image to a byte array directly using ExportByteArray. So:

Iconize[
ExportByteArray[ExampleData[{"TestImage", "Lena"}], "JPG"],
"lena 00 compressed"
]


I don't know what the issue is (perhaps a character encoding issue), and it would be worth reporting it to support. As a workaround, you can also compress the string:

Iconize[
Compress @ ExportString[ExampleData[{"TestImage", "Lena"}], "JPG"],
"lena 00 compressed"
]


The import still works after quiting and reopening.

Probably a better approach is to convert to a ByteArray instead of a compressed string, since the JPEG is already compressed. The byte array will be smaller and faster to convert back to the JPG string.
Iconize[

• Thanks to your answer, I have investigated in another direction and I finally discovered ExportByteArray[...,"JPG"] and ImportByteArray[...,"JPG"] which seem to be better in all points of view. Do I post a answer or do you prefer to complete yours ? May 20 '18 at 18:53