Closed
Description
Describe the bug (mandatory)
Annot.get_pixmap
returns a pixmap object without a owner.
To Reproduce (mandatory)
import fitz
doc = fitz.Document()
page = doc.new_page()
page.add_line_annot((1, 1), (100, 100))
page = doc.reload_page(page)
annot = page.first_annot
p = annot.get_pixmap()
print(p.alpha)
And I get RuntimeError:
Traceback (most recent call last):
File "/projectpath/test_pymupdf.py", line 11, in <module>
print(p.alpha)
File "/projectpath/.venv/lib/python3.10/site-packages/fitz/fitz.py", line 7422, in alpha
EnsureOwnership(self)
File "/projectpath/.venv/lib/python3.10/site-packages/fitz/fitz.py", line 2944, in EnsureOwnership
raise RuntimeError("object destroyed")
RuntimeError: object destroyed
Expected behavior (optional)
No error thrown.
Your configuration (mandatory)
3.10.0 (default, Oct 5 2021, 23:09:35) [GCC 11.2.1 20210816 [revision 056e324ce46a7924b5cf10f61010cf9dd2ca10e9]]
linux
PyMuPDF 1.19.6: Python bindings for the MuPDF 1.19.0 library.
Version date: 2022-03-03 00:00:01.
Built for Python 3.10 on linux (64-bit).
Additional context (optional)
It seems that the problem is this snippet in fitz.py
:
def get_pixmap(
self,
matrix: AnyType = None,
dpi: AnyType = None,
colorspace: "Colorspace" = None,
alpha: int = 0,
) -> "Pixmap":
"""annotation Pixmap"""
CheckParent(self)
cspaces = {"gray": csGRAY, "rgb": csRGB, "cmyk": csCMYK}
if type(colorspace) is str:
colorspace = cspaces.get(colorspace.lower(), None)
if dpi:
matrix = Matrix(dpi / 72, dpi / 72)
val = _fitz.Annot_get_pixmap(self, matrix, dpi, colorspace, alpha)
if dpi:
val.set_dpi(dpi, dpi)
return val
val.thisown
isn't set to True
, as compared to
def get_pixmap(
self,
matrix: AnyType = None,
colorspace: "Colorspace" = None,
alpha: int = 0,
clip: rect_like = None,
) -> "Pixmap":
val = _fitz.DisplayList_get_pixmap(self, matrix, colorspace, alpha, clip)
val.thisown = True
return val