Young
Young

Reputation: 31

Image export and import incoherence in mathematica

Happy for the incoming new year, everyone!

I run the following code in Mathematica 11 but I cannot understand the output. b and b1 are of the same size and look the same when shown in characters, but Mathematica regards them differently. Could you give me some advice on why this happens?

a = Import["ExampleData/rose.gif"];
b = ExportString[a, "PNG"];
c = ImportString[b, "PNG"];
Export["D:/flower.txt", b];
b1 = Import["D:/flower.txt"];
ByteCount /@ {b, b1}
b == b1

Best regards!

Upvotes: 3

Views: 165

Answers (1)

Chris Degnen
Chris Degnen

Reputation: 8655

To export to text you need b in string form. Converting to PNG and Base64 works.

a = Import["ExampleData/rose.gif"];
b = ExportString[a, {"Base64", "PNG"}]
c = ImportString[b, {"Base64", "PNG"}]
Export["D:/flower.txt", b, "String"];
b1 = Import["D:/flower.txt", "String"];
ByteCount /@ {b, b1}
b == b1
{41016, 41016}
True

Happy New Year!

Upvotes: 4

Related Questions