如何从图像中提取原始 []uint8?
最佳答案
根据定义,8 位整数的大小为 8 位(或 1 个字节)。
(编辑删除错误信息,我将在下面为后代重新发布。)
输出的字符串表示不是每个数字一个字符 - 它是几个(例如,您首先列出的 int - 65
- 由 三个 个字符表示 -一个 6、一个 5 和一个空格。这将使预期大小增加三倍,从 300k 到 900k。
至于其余部分,我认为(如 icza 在评论中所说)图像压缩可能是罪魁祸首。
(我最初作为回答的一部分发布的无关信息是:
Go has two character types,
byte
andrune
. A byte being used to store a character is the same size as a byte being used to store an integer - both are 8 bits. But a character being stored as arune
is going to be 32 bits (see https://www.callicoder.com/golang-basic-types-operators-type-conversion/). So, if the characters being written out arerune
s, that would explain a four-fold increase in size (because 32 / 8 = 4)...
关于go - 无法将图像转换为 []uint8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57277634/