Aprimorar o Processamento de Imagens com a API Moderna
Introdução
Atualmente, a biblioteca Aspose.Slides for C++ tem dependências em sua API pública nas seguintes classes de System::Drawing:
A partir da versão 24.4, essa API pública foi declarada obsoleta.
Para eliminar as dependências de System::Drawing na API pública, adicionamos a chamada “Modern API”. Métodos com System::Drawing::Image e System::Drawing::Bitmap foram declarados obsoletos e devem ser substituídos pelos métodos correspondentes da Modern API. Métodos com System::Drawing::Graphics foram declarados obsoletos e não têm substituição direta na Modern API.
Nas versões atuais, trate a API pública que depende de tipos System::Drawing como legado/obsoleta. Use a Modern API para novo código e ao migrar fluxos de trabalho existentes de processamento de imagens.
Modern API
Adicionamos as seguintes classes e enums à API pública:
- Aspose::Slides::IImage - representa a imagem raster ou vetorial.
- Aspose::Slides::ImageFormat - representa o formato de arquivo da imagem.
- Aspose::Slides::Images - métodos para instanciar e trabalhar com a interface IImage.
Use GetImage para renderizar um único slide ou forma. Use GetImages para renderizar vários slides da apresentação. Use os métodos de Images para carregar imagens, AddImage com IImage para adicioná‑las a uma apresentação e ReplaceImage com IImage para atualizar uma imagem existente na apresentação.
Um cenário típico de uso da nova API pode ser o seguinte:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
// instanciar uma instância descartável de IImage a partir do arquivo no disco.
System::SharedPtr<IImage> image = Images::FromFile(u"image.png");
// criar uma imagem PowerPoint adicionando uma instância de IImage às imagens da apresentação.
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
// adicionar uma forma de imagem no slide #1
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
// obter uma instância de IImage que representa o slide #1.
auto slideImage = pres->get_Slide(0)->GetImage(System::Drawing::Size(1920, 1080));
// salvar a imagem no disco.
slideImage->Save(u"slide1.jpeg", Aspose::Slides::ImageFormat::Jpeg);
Substituindo Código Antigo pela Modern API
Para facilitar a transição, a interface do novo IImage repete as assinaturas separadas das classes System::Drawing::Image e System::Drawing::Bitmap. Em geral, você só precisará substituir a chamada ao método antigo que usa System::Drawing pelo novo.
Obtendo uma Miniatura de Slide
API legada/obsoleta:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->GetThumbnail()->Save(u"slide1.png");
API Moderna:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->GetImage()->Save(u"slide1.png");
Obtendo uma Miniatura de Forma
API legada/obsoleta:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->get_Shape(0)->GetThumbnail()->Save(u"shape.png");
API Moderna:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->get_Shape(0)->GetImage()->Save(u"shape.png");
Obtendo uma Miniatura de Apresentação
API legada/obsoleta:
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 Moderna:
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);
}
Adicionando uma Imagem a uma Apresentação
API legada/obsoleta:
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 Moderna:
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);
Métodos/Propriedades Obsoletos e Sua Substituição na Modern API
Classe Presentation
| Assinatura do Método | Assinatura do Método de Substituição |
|---|---|
| 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) | No Modern API replacement |
| Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format, System::SharedPtr<Export::ISaveOptions> options) | No Modern API replacement |
Classe Slide
| Assinatura do Método | Assinatura do Método de Substituição |
|---|---|
| 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) | No Modern API replacement |
| RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, float scaleX, float scaleY) | No Modern API replacement |
| RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, System::Drawing::Size renderingSize) | No Modern API replacement |
Classe Shape
| Assinatura do Método | Assinatura do Método de Substituição |
|---|---|
| GetThumbnail() | GetImage() |
| GetThumbnail(ShapeThumbnailBounds bounds, float scaleX, float scaleY) | GetImage(ShapeThumbnailBounds bounds, float scaleX, float scaleY) |
Classe ImageCollection
| Assinatura do Método | Assinatura do Método de Substituição |
|---|---|
| AddImage(System::SharedPtr<System::Drawing::Image> image) | AddImage(System::SharedPtr<IImage> image) |
Classe PPImage
| Assinatura do Método | Assinatura do Método de Substituição |
|---|---|
| ReplaceImage(System::SharedPtr<System::Drawing::Image> newImage) | ReplaceImage(System::SharedPtr<Aspose::Slides::IImage> newImage) |
| get_SystemImage() | get_Image() |
Classe PatternFormat
| Assinatura do Método | Assinatura do Método de Substituição |
|---|---|
| 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) |
Classe IPatternFormatEffectiveData
| Assinatura do Método | Assinatura do Método de Substituição |
|---|---|
| GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) | GetTileIImage(System::Drawing::Color background, System::Drawing::Color foreground) |
Suporte de API para System::Drawing::Graphics
Métodos com System::Drawing::Graphics foram declarados obsoletos e não têm substituição direta na Modern API.
Use os métodos de renderização de imagem da Modern API em vez da API que renderiza para System::Drawing::Graphics:
- 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)
FAQ
Por que System::Drawing::Graphics foi removido?
O suporte a System::Drawing::Graphics está obsoleto na API pública para unificar o trabalho com renderização e imagens, eliminar dependências específicas de plataforma e adotar uma abordagem multiplataforma com IImage. Use GetImage ou GetImages em vez de renderizar para System::Drawing::Graphics.
Qual é o benefício prático de IImage em comparação com System::Drawing::Image/System::Drawing::Bitmap?
IImage unifica o trabalho com imagens raster e vetoriais, simplifica a gravação em vários formatos via ImageFormat, reduz a dependência de System::Drawing e torna o código mais portátil entre ambientes.
A Modern API afetará o desempenho da geração de miniaturas?
A troca de GetThumbnail para GetImage não piora os cenários: os novos métodos oferecem as mesmas capacidades de produzir imagens com opções e tamanhos, mantendo o suporte às opções de renderização. O ganho ou perda específico depende do cenário, mas funcionalmente as substituições são equivalentes.