Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image PNG像素计数不同?_Image_Png - Fatal编程技术网

Image PNG像素计数不同?

Image PNG像素计数不同?,image,png,Image,Png,我有一个PNG文件。我解压缩了IDAT块,并将其作为16位颜色(每像素16位)读取,并将其保存在一维数组中。PNG文件是126x128(wxh)。但是我得到的像素数(数组长度)是16192。因此: 16192 <-- pixel I got 126x128=16128 <-- pixel using width and height ----- 64 <-- difference 16192如果你不告诉我们细节,很难说(你

我有一个PNG文件。我解压缩了IDAT块,并将其作为16位颜色(每像素16位)读取,并将其保存在一维数组中。PNG文件是126x128(wxh)。但是我得到的像素数(数组长度)是16192。因此:

        16192 <-- pixel I got
126x128=16128 <-- pixel using width and height
        -----
           64 <-- difference

16192如果你不告诉我们细节,很难说(你是如何计算像素数量的?)

一种可能的解释是,您忘记了考虑每个PNG行前面都有一个字节,该字节告诉应用于该行的“过滤器()。因此,IDAT块内的总字节数(在ZLIB压缩之前;不要忘记可能有许多IDAT块,您必须将它们全部追加)是


如果您的图像是16位灰度(字节/像素=2),并且您正在计算像素=行x列=字节/字节/字节/像素,那么这将解释差异。

Leonboy说得对。每行的开头都有一个额外的字节,这样就可以对图像的不同部分以不同的方式对行进行预过滤。顺便说一句,你应该为此负责。:-)
Bytes = Rows x (1 +  Cols x BytesPerPixel)