چگونه تصاویر راستر را در Python ایجاد کنیم
چگونه تصاویر راستر را در Python ایجاد کنیم
Pass ImageSaveOptions به to_image() در PsDocument یا XpsDocument به عنوان صادرات یک تصویر راستر. ImageSaveOptions پذیرفته شده A format تگ ها ("png" یا "jpeg") و A dpi به روش بازگشت می شود. bytes تصویر را در قالب کدگذاری شده قرار دهید.در حالت پیش فرض DPI 96 است؛ برای تولید با رزولوشن بالاتر از 150 یا 300 استفاده کنید.
خروجی PNG از 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 از 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))تنظیم DPI
استفاده از آن dpi اموال از ImageSaveOptions:
from aspose.page.ps.output import ImageSaveOptions
high_res = ImageSaveOptions(format="png", dpi=300)
web_res = ImageSaveOptions(format="png", dpi=96)