CdrImage

Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.DataStreamSupporter, com.aspose.imaging.Image, com.aspose.imaging.VectorImage, com.aspose.imaging.VectorMultipageImage

All Implemented Interfaces: com.aspose.imaging.fileformats.cdr.ICdrImage

public class CdrImage extends VectorMultipageImage implements ICdrImage

CorelDRAW CDR 矢量图像格式支持的 API 是面向矢量图形开发者的必备工具包。该 API 实现了对 CDR 文件的无缝处理,支持文本、线条、形状、图像、颜色和效果等多种元素的存储与操作。凭借其全面的功能,开发者能够高效地处理图像内容的矢量表示,在以编程方式创建和编辑 CorelDRAW 矢量图形时确保精确性和灵活性。

构造函数

构造函数描述
CdrImage(InputStream stream, LoadOptions loadOptions)通过使用流和 loadOptions 参数初始化新实例,轻松开始使用 CdrImage 类。
CdrImage(System.IO.Stream stream, LoadOptions loadOptions)通过使用流和 loadOptions 参数初始化新实例,轻松开始使用 CdrImage 类。

方法

方法描述
getDefaultPage()使用此用户友好的属性,轻松检索图像的默认页。
isCached()轻松确定对象的数据是否已缓存,消除读取数据的需求。
getBitsPerPixel()使用此用户友好的属性,轻松获取图像的位深度。
getPageCount()使用此直观属性,轻松获取或更新图像的总页数。
getPages()使用此直观属性,顺畅获取图像的页面。
getCdrDocument()使用此直观属性,轻松获取或更新 CDR 文档。
getFileFormat()使用此直观属性,轻松检索图像的文件格式。
getWidth()获取图像宽度。
getHeight()获取图像高度。
cacheData()使用此用户友好的方法,轻松缓存数据,以防止从底层来源再次加载。
setPalette(IColorPalette palette, boolean updateColors)使用此直观方法自定义图像的颜色调色板。

Example: The following example shows how to cache all pages of a CDR image.

String dir = "c:\\temp\\";

// 从 CDR 文件加载图像。
com.aspose.imaging.fileformats.cdr.CdrImage image = (com.aspose.imaging.fileformats.cdr.CdrImage) com.aspose.imaging.Image.load(dir + "sample.cdr");
try {
    // 此调用仅缓存默认页面。
    image.cacheData();

    // 缓存所有页面,以防止从底层数据流进行额外的数据加载。
    for (com.aspose.imaging.fileformats.cdr.CdrImagePage page : image.getPages()) {
        page.cacheData();
    }
} finally {
    image.dispose();
}

CdrImage(InputStream stream, LoadOptions loadOptions)

public CdrImage(InputStream stream, LoadOptions loadOptions)

通过使用流和 loadOptions 参数初始化新实例,轻松开始使用 CdrImage 类。此方式非常适合希望以便捷方式从各种数据源加载 CDR 图像并根据需要自定义加载过程的开发者。

Parameters:

参数类型描述
java.io.InputStream流。
loadOptionsLoadOptions加载选项。

CdrImage(System.IO.Stream stream, LoadOptions loadOptions)

public CdrImage(System.IO.Stream stream, LoadOptions loadOptions)

通过使用流和 loadOptions 参数初始化新实例,轻松开始使用 CdrImage 类。此方式非常适合希望以便捷方式从各种数据源加载 CDR 图像并根据需要自定义加载过程的开发者。

Parameters:

参数类型描述
com.aspose.ms.System.IO.Stream流。
loadOptionsLoadOptions加载选项。

getDefaultPage()

public Image getDefaultPage()

使用此用户友好的属性,轻松检索图像的默认页。对于希望快速访问图像主页、确保高效导航和管理的开发者而言,这一功能堪称完美。

Returns: Image - the default page.

isCached()

public boolean isCached()

轻松确定对象的数据是否已缓存,消除读取数据的需求。对于希望通过高效利用缓存数据来优化性能、确保更快访问信息的开发者而言,这一点尤为理想。

Returns: 布尔值 - 如果对象的数据已缓存则为 true;否则为 false

getBitsPerPixel()

public int getBitsPerPixel()

使用此用户友好的属性,轻松获取图像的位深度。该属性非常适合希望确定图像细节级别或颜色深度、确保准确处理和操作的开发者。

Returns: int - 图像每像素位数。

getPageCount()

public final int getPageCount()

使用此直观属性,轻松获取或更新图像的总页数。对于希望动态管理多页图像、确保高效导航和操作图像内容的开发者而言,这一点非常理想。

Returns: int - 页数。

getPages()

public final Image[] getPages()

使用此直观属性无缝检索图像的各页。适用于希望访问和操作多页图像中单个页面的开发者,确保高效的导航和处理。

Returns: com.aspose.imaging.Image[] - 页面。

Example: The following example shows how to export a single page of CDR document to PDF.

int pageNumber = 0;
String dir = "c:\\aspose.imaging\\java\\issues\\1445'\\";
String inputCdrFileName = dir + "tiger.cdr";
String outputPdfFileName = dir + "tiger.cdr.page" + pageNumber + ".pdf";

com.aspose.imaging.fileformats.cdr.CdrImage image = (com.aspose.imaging.fileformats.cdr.CdrImage) com.aspose.imaging.Image.load(inputCdrFileName);
try {
    com.aspose.imaging.Image imagePage = image.getPages()[pageNumber];

    com.aspose.imaging.imageoptions.PdfOptions pdfOptions = new com.aspose.imaging.imageoptions.PdfOptions();
    com.aspose.imaging.imageoptions.CdrRasterizationOptions rasterizationOptions = new com.aspose.imaging.imageoptions.CdrRasterizationOptions();
    rasterizationOptions.setTextRenderingHint(com.aspose.imaging.TextRenderingHint.SingleBitPerPixel);
    rasterizationOptions.setSmoothingMode(com.aspose.imaging.SmoothingMode.None);
    rasterizationOptions.setPageWidth(image.getWidth());
    rasterizationOptions.setPageHeight(image.getHeight());

    pdfOptions.setVectorRasterizationOptions(rasterizationOptions);

    imagePage.save(outputPdfFileName, pdfOptions);
}
finally {
    image.close();
}

getCdrDocument()

public final CdrDocument getCdrDocument()

使用此直观属性,轻松获取或更新 CDR 文档。对于希望访问或修改 CDR 文档、在应用中实现灵活高效操作的开发者而言,这一点非常理想。

Returns: CdrDocument - the CDR document.

getFileFormat()

public long getFileFormat()

使用此直观属性,轻松检索图像的文件格式。对于希望动态确定图像格式、确保在应用中兼容性和精确处理的开发者而言,这一点非常理想。

Returns: long

getWidth()

public int getWidth()

获取图像宽度。

值:图像宽度。

Returns: int - 图像宽度。

getHeight()

public int getHeight()

获取图像高度。

值:图像高度。

Returns: int - 图像高度。

cacheData()

public void cacheData()

使用此用户友好的方法,轻松缓存数据,以防止从底层来源再次加载。对于希望通过预加载数据来优化性能、确保更快访问和更流畅操作的开发者而言,这一点非常理想。DataStreamSupporter.DataStreamContainer(DataStreamSupporter.getDataStreamContainer/DataStreamSupporter.setDataStreamContainer\_internalized(StreamContainer))。

Example: The following example shows how to cache all pages of a CDR image.

String dir = "c:\\temp\\";

// 从 CDR 文件加载图像。
com.aspose.imaging.fileformats.cdr.CdrImage image = (com.aspose.imaging.fileformats.cdr.CdrImage) com.aspose.imaging.Image.load(dir + "sample.cdr");
try {
    // 此调用仅缓存默认页面。
    image.cacheData();

    // 缓存所有页面,以防止从底层数据流进行额外的数据加载。
    for (com.aspose.imaging.fileformats.cdr.CdrImagePage page : image.getPages()) {
        page.cacheData();
    }
} finally {
    image.dispose();
}

setPalette(IColorPalette palette, boolean updateColors)

public void setPalette(IColorPalette palette, boolean updateColors)

使用此直观方法自定义图像的颜色调色板。适用于希望动态应用特定配色方案或调整的开发者,确保对图像视觉外观的精确控制。

Parameters:

参数类型描述
paletteIColorPalette要设置的调色板。
updateColorsboolean如果设置为 true,颜色将根据新调色板进行更新;否则颜色索引保持不变。请注意,如果某些索引没有对应的调色板条目,未更改的索引可能在加载时导致图像崩溃。