简体   繁体   English

Uint8Array 未显示 PNG 文件的正确值

[英]Uint8Array is not showing correct values for PNG file

I am trying to decode a PNG file coming as an Uint8Array from the backend using javascript in the browser.我正在尝试使用浏览器中的 javascript 从后端解码作为 Uint8Array 的 PNG 文件。 Slicing the Uint8Array from 15~28 and console.logging the values prints this : [82, 0, 0, 1, 0, 0, 0, 1, 0, 8, 6, 0, 0].将 Uint8Array 从 15~28 切片并 console.logging 打印出以下内容:[82, 0, 0, 1, 0, 0, 0, 1, 0, 8, 6, 0, 0]。 If I sum the bytes from 0~4 in this array I obtain 83 which should be the value for the width, but the width is 256px.如果我将这个数组中 0~4 的字节相加,我会得到 83,这应该是宽度的值,但宽度是 256px。

With the same file I tried decoding it on this website https://www.nayuki.io/page/png-file-chunk-inspector it show [00 00 00 0d 49 48 44 52 00 00 01 00 00] these values for 15~28.使用相同的文件,我尝试在此网站https://www.nayuki.io/page/png-file-chunk-inspector上对其进行解码,它显示 [00 00 00 0d 49 48 44 52 00 00 01 00 00] 这些值为15~28。 But it correctly says that the png has a width of 256px.但它正确地说 png 的宽度为 256px。 Which I also don't understand how, adding 00+00+00+0d results a value of 13 in decimal.我也不明白如何添加 00+00+00+0d 导致十进制值 13 。

So far I don't really understand what happens.到目前为止,我真的不明白会发生什么。 The PNG standard says that http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html the IHDR width is a 4-byte integer from 15~19 but in practice it is not working. PNG标准说http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html IHDR宽度是15~19的4字节整数,但实际上它不起作用。

在此处输入图像描述

Looking through the image decoding website you linked, it seems that the first 4 hex values represent how many bytes are in the rest of the string: this is why the first 4 work out to 13, because there should be 13 bytes in the IHDR.查看您链接的图像解码网站,前 4 个十六进制值似乎代表字符串的其余部分有多少字节:这就是前 4 个工作为 13 个的原因,因为 IHDR 中应该有 13 个字节。 Additionally, the next 4 [49, 48, 44, 52] stay the same between your image and all of the 'good' examples on the website.此外,接下来的 4 个 [49, 48, 44, 52] 在您的图像和网站上所有“好”示例之间保持不变。 The real place where the width and height are stored are the two bytes after that, which are both 00 00 01 00. This value 00000100 works out to be 256, as per this converter实际存储宽度和高度的位置是之后的两个字节,它们都是 00 00 01 00。根据这个转换器,这个值00000100的计算结果是 256

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM