go - 无法将图像转换为 []uint8

标签 go

如何从图像中提取原始 []uint8?

最佳答案

根据定义,8 位整数的大小为 8 位(或 1 个字节)。

(编辑删除错误信息,我将在下面为后代重新发布。)

输出的字符串表示不是每个数字一个字符 - 它是几个(例如,您首先列出的 int - 65 - 由 三个 个字符表示 -一个 6、一个 5 和一个空格。这将使预期大小增加三倍,从 300k 到 900k。

至于其余部分,我认为(如 icza 在评论中所说)图像压缩可能是罪魁祸首。


(我最初作为回答的一部分发布的无关信息是:

Go has two character types, byte and rune. 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 a rune is going to be 32 bits (see https://www.callicoder.com/golang-basic-types-operators-type-conversion/). So, if the characters being written out are runes, that would explain a four-fold increase in size (because 32 / 8 = 4)...

关于go - 无法将图像转换为 []uint8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57277634/

相关文章:

google-app-engine - 在 appspot.com 上解析 64 位 int 与在本地主机上不同?

go - 为什么 Go 需要这么多 CPU 来构建一个包?

go - 如何将 int32 unicode 转换为字符串

go - 如何使用golang etcd客户端创建目录节点?

amazon-web-services - 使用 AWS EC2 Golang GO 端点在 Docker 部署上获取 JSON 时出现问题

go - 带有指针接收器的方法

Go 语言字符串常量

go - 在生产者速度慢,消费者速度快的情况下,如何处理 channel 关闭同步?

go - 如何输出在 Docker-Compose.yml 的 yaml 解码中引发错误的行?

azure - 如何在 Azure SDK 中使用 "expand"参数?