【问题标题】:Image export and import incoherence in mathematicaMathematica 中的图像导出和导入不连贯
【发布时间】:2017-12-31 12:45:12
【问题描述】:

大家新年快乐!

我在 Mathematica 11 中运行以下代码,但我无法理解输出。 b 和 b1 大小相同,在字符中显示时看起来相同,但 Mathematica 对它们的看法不同。您能给我一些关于为什么会发生这种情况的建议吗?

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

最好的问候!

【问题讨论】:

  • 我怀疑这里正在进行整数-浮点数(和反向)转换,并带有一些舍入错误。

标签: image import export wolfram-mathematica


【解决方案1】:

要导出为文本,您需要字符串形式的b。转换为 PNG Base64 有效。

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

新年快乐!

【讨论】:

    猜你喜欢
    • 2010-11-03
    • 2014-12-12
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多