-
Hi, I've got a PNG image described as numpy ndarray. To try to understand how to proceed I used this article and the PyMuPDF doc https://code.activestate.com/recipes/580630-saving-a-numpy-array-to-png-image-using-fitz-mupdf/ https://documentation.help/PyMuPDF/page.html but when I run this code I get the error about "image format not recognized".
The assignement to the variable image_np_arr doesn't throw any error (I had just to switch to .tobytes() because the code told me .tostring() was deprecated) As you can see the image is a PNG and there are 4 bands
How can I fix this? Or how to troubleshoot it more? Thanks in advance, Alex |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
You are using the wrong object constructor pattern when defining the pixmap: review the brackets!
Your argument falls in none of these categories. |
Beta Was this translation helpful? Give feedback.
-
This error means |
Beta Was this translation helpful? Give feedback.
This error means
width * height * (n + alpha)
does not equal the length of the bytes object, which is used assamples
in the constructor.The factor
(n + alpha)
means: n = 3 for RGB, 1 for GRAY, 4 for CMYK,alpha
is 0 or 1 depending on whether an alpha channel is present.