Làm thế nào để tạo ra hình ảnh Raster trong Python
Làm thế nào để tạo ra hình ảnh Raster trong Python
Pass ImageSaveOptions để to_image() trên PsDocument hoặc XpsDocument xuất khẩu như Hình ảnh rác. ImageSaveOptions chấp nhận a format Tinh ("png" hoặc "jpeg") và A dpi Phương pháp: phương pháp trở lại bytes - Có hình ảnh mã hóa: default DPI là 96; sử dụng 150 hoặc 300 cho sản lượng độ phân giải cao hơn.
PNG xuất phát từ 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 xuất 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))Đặt DPI
Sử dụng The dpi Tài sản của ImageSaveOptions:
from aspose.page.ps.output import ImageSaveOptions
high_res = ImageSaveOptions(format="png", dpi=300)
web_res = ImageSaveOptions(format="png", dpi=96)