工作表转图像 为渲染的图像设置像素格式
Contents
[
Hide
]
有时你在将工作表渲染为图像格式时希望指定像素格式。默认情况下,Aspose.Cells for Python via .NET使用每像素32位。您可以使用渲染图像的选项来自定义像素格式(位深度)。
请参阅下面的示例代码,演示了如何在渲染工作表的图像时设置所需的像素格式。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
from aspose.cells.drawing import ImageType | |
from aspose.cells.rendering import ImageOrPrintOptions, SheetRender | |
from aspose.pydrawing.imaging import PixelFormat | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Load an Excel file | |
wb = Workbook(sourceDir + "sampleSetPixelFormatRenderedImage.xlsx") | |
# Access first worksheet | |
ws = wb.worksheets[0] | |
# Set the ImageOrPrintOptions with desired pixel format (24 bits per pixel) and image format type | |
opts = ImageOrPrintOptions() | |
opts.pixel_format = PixelFormat.FORMAT_24BPP_RGB | |
opts.image_type = ImageType.TIFF | |
# Instantiate SheetRender object based on the first worksheet | |
sr = SheetRender(ws, opts) | |
# Save the image (first page of the sheet) with the specified options | |
sr.to_image(0, outputDir + "outputSetPixelFormatRenderedImage.tiff") |