现代 API
Contents
[
Hide
]
介绍
目前,Aspose.Slides for C++ 库的公共 API 依赖于以下来自 System::Drawing 的类:
从 24.4 版本开始,此公共 API 被声明为过时。
为了摆脱公共 API 中对 System::Drawing 的依赖,我们添加了所谓的“现代 API”。使用 System::Drawing::Image 和 System::Drawing::Bitmap 的方法被声明为过时,将被现代 API 中的相应方法替代。使用 System::Graphics 的方法被声明为过时,其支持将从公共 API 中移除。
带有对 System::Drawing 依赖的过时公共 API 将在 24.8 版本中移除。
现代 API
将以下类和枚举添加到公共 API 中:
- Aspose::Slides::IImage - 代表光栅或矢量图像。
- Aspose::Slides::ImageFormat - 代表图像的文件格式。
- Aspose::Slides::Images - 实例化和处理 IImage 接口的方法。
使用新 API 的典型场景可能如下所示:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
// 从磁盘上的文件实例化可处置的 IImage 实例。
System::SharedPtr<IImage> image = Images::FromFile(u"image.png");
// 通过将 IImage 实例添加到演示文稿的图像中来创建 PowerPoint 图像。
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
// 在幻灯片 #1 上添加图片形状
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
// 获取表示幻灯片 #1 的 IImage 实例。
auto slideImage = pres->get_Slide(0)->GetImage(System::Drawing::Size(1920, 1080));
// 将图像保存到磁盘上。
slideImage->Save(u"slide1.jpeg", Aspose::Slides::ImageFormat::Jpeg);
用现代 API 替换旧代码
为了便于过渡,新 IImage 的接口重复了 Image 和 Bitmap 类的单独签名。一般来说,您只需用新方法替换旧的使用 System::Drawing 的方法调用。
获取幻灯片缩略图
使用过时 API 的代码:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->GetThumbnail()->Save(u"slide1.png");
现代 API:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->GetImage()->Save(u"slide1.png");
获取形状缩略图
使用过时 API 的代码:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->get_Shape(0)->GetThumbnail()->Save(u"shape.png");
现代 API:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->get_Shape(0)->GetImage()->Save(u"shape.png");
获取演示文稿缩略图
使用过时 API 的代码:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
auto bitmaps = pres->GetThumbnails(System::MakeObject<RenderingOptions>(), System::Drawing::Size(1980, 1028));
for (int32_t index = 0; index < bitmaps->get_Length(); index++)
{
System::SharedPtr<System::Drawing::Bitmap> thumbnail = bitmaps[index];
thumbnail->Save(System::String::Format(u"slide_{0}.png", index), System::Drawing::Imaging::ImageFormat::get_Png());
}
现代 API:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
auto images = pres->GetImages(System::MakeObject<RenderingOptions>(), System::Drawing::Size(1980, 1028));
for (int32_t index = 0; index < images->get_Length(); index++)
{
System::SharedPtr<IImage> thumbnail = images[index];
thumbnail->Save(System::String::Format(u"slide_{0}.png", index), Aspose::Slides::ImageFormat::Png);
}
向演示文稿中添加图片
使用过时 API 的代码:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
System::SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(u"image.png");
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
现代 API:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
System::SharedPtr<Aspose::Slides::IImage> image = Aspose::Slides::Images::FromFile(u"image.png");
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
要删除的方法/属性及其在现代 API 中的替代
Presentation 类
方法签名 | 替代方法签名 |
---|---|
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options) | GetImages(System::SharedPtr<Export::IRenderingOptions> options) |
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides) |
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) |
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, float scaleX, float scaleY) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, float scaleX, float scaleY) |
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) |
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, System::Drawing::Size imageSize) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, System::Drawing::Size imageSize) |
Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format) | 将完全删除 |
Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format, System::SharedPtr<Export::ISaveOptions> options) | 将完全删除 |
Slide 类
方法签名 | 替代方法签名 |
---|---|
GetThumbnail() | GetImage() |
GetThumbnail(float scaleX, float scaleY) | GetImage(float scaleX, float scaleY) |
GetThumbnail(System::Drawing::Size imageSize) | GetImage(System::Drawing::Size imageSize) |
GetThumbnail(System::SharedPtr<Export::ITiffOptions> options) | GetImage(System::SharedPtr<Export::IRenderingOptions> options) |
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options) | GetImage(System::SharedPtr<Export::IRenderingOptions> options) |
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) | GetImage(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) |
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) | GetImage(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) |
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics) | 将完全删除 |
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, float scaleX, float scaleY) | 将完全删除 |
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, System::Drawing::Size renderingSize) | 将完全删除 |
Shape 类
方法签名 | 替代方法签名 |
---|---|
GetThumbnail() | GetImage() |
GetThumbnail(ShapeThumbnailBounds bounds, float scaleX, float scaleY) | GetImage(ShapeThumbnailBounds bounds, float scaleX, float scaleY) |
ImageCollection 类
方法签名 | 替代方法签名 |
---|---|
AddImage(System::SharedPtr<System::Drawing::Image> image) | AddImage(System::SharedPtr<IImage> image) |
PPImage 类
方法签名 | 替代方法签名 |
---|---|
ReplaceImage(System::SharedPtr<System::Drawing::Image> newImage) | ReplaceImage(System::SharedPtr<Aspose::Slides::IImage> newImage) |
get_SystemImage() | get_Image() |
PatternFormat 类
方法签名 | 替代方法签名 |
---|---|
GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) | GetTile(System::Drawing::Color background, System::Drawing::Color foreground) |
GetTileImage(System::Drawing::Color styleColor) | GetTile(System::Drawing::Color styleColor) |
IPatternFormatEffectiveData 类
方法签名 | 替代方法签名 |
---|---|
GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) | GetTileIImage(System::Drawing::Color background, System::Drawing::Color foreground) |
API 对 System::Drawing::Graphics 的支持将被弃用
使用 System::Drawing::Graphics 的方法被声明为过时,其支持将从公共 API 中移除。
使用它的 API 部分将被移除:
- Slide::RenderToGraphics(System::SharedPtr<Export::IRenderingOptions>, System::SharedPtr<System::Drawing::Graphics>)
- Slide::RenderToGraphics(System::SharedPtr<Export::IRenderingOptions>, System::SharedPtr<System::Drawing::Graphics>, float, float)
- Slide::RenderToGraphics(System::SharedPtr<Export::IRenderingOptions>, System::SharedPtr<System::Drawing::Graphics>, System::Drawing::Size)