Cum să generați imagini raster în Python
Cum să generați imagini raster în Python
Pasă de trecere. ImageSaveOptions la … în to_image() în PsDocument sau de: XpsDocument pentru export ca: o imagine raster. ImageSaveOptions acceptă o format string ("png" sau de: "jpeg") și a) în cazul de: dpi Metoda returnează: bytes Conţinând imaginea codificată. DPI este 96; utilizați 150 sau 300 pentru o ieșire cu rezoluție mai mare.
PNG ieșire din PS
from pathlib import Path
from aspose.page.ps.document import PsDocument
from aspose.page.ps.output import ImageSaveOptions
ps = PsDocument.from_file("input.ps")
opts = ImageSaveOptions(format="png", dpi=150)
Path("output.png").write_bytes(ps.to_image(opts))JPEG ieșire de la XPS
from pathlib import Path
from aspose.page.xps.document import XpsDocument
from aspose.page.ps.output import ImageSaveOptions
xps = XpsDocument.from_file("input.xps")
opts = ImageSaveOptions(format="jpeg", dpi=96)
Path("output.jpg").write_bytes(xps.to_image(opts))Setarea DPI
Foloseşte-l. dpi proprietatea de ImageSaveOptions:
from aspose.page.ps.output import ImageSaveOptions
high_res = ImageSaveOptions(format="png", dpi=300)
web_res = ImageSaveOptions(format="png", dpi=96)