Este artigo orienta sobre como extrair imagens de PowerPoint com C# REST API. Você aprenderá a recuperar automaticamente imagens no PowerPoint com interface C# REST usando um SDK de nuvem baseado em .NET. Ele compartilhará detalhes para extrair todas as imagens ou buscar imagens selecionadas da apresentação.
Pré-requisito
Download Aspose.Slides Cloud SDK for Dotnet to retrieve images from the presentation
Configure o projeto C# com o SDK acima para extrair imagens
Etapas para extrair fotos do PowerPoint com API REST C#
- Inicialize o objeto SlidesApi para extrair imagens usando o ID do cliente e o segredo
- Carregue o arquivo PowerPoint com imagens para o armazenamento em nuvem Aspose
- Baixe todas as imagens da apresentação do PowerPoint em um arquivo ZIP usando o método DownloadImagesDefaultFormat()
- Salve o arquivo ZIP contendo todas as imagens extraídas no armazenamento local
- Baixe uma única imagem da apresentação do PowerPoint
- Salve a imagem única extraída como um arquivo PNG no armazenamento local
Estas etapas descrevem como buscar imagens de apresentação do PowerPoint com API baseada em C# .NET. Inicialize o objeto SlidesApi, carregue a apresentação no servidor, baixe todas as imagens como um fluxo ZIP da resposta da API e salve-as no disco. Use o método DownloadImageDefaultFormat() para buscar a imagem desejada apenas fornecendo o índice da imagem na apresentação.
Código para extrair imagens em apresentações com serviço RESTful C#
// Importing the Aspose.Slides.Cloud.Sdk library to work with PowerPoint files in the cloud | |
using Aspose.Slides.Cloud.Sdk; | |
using System.IO; // Importing System.IO for file handling operations | |
namespace PresentationProcessor | |
{ | |
class ExtractImages | |
{ | |
static void Main(string[] args) | |
{ | |
// Creating an instance of the SlidesApi class using API credentials (API Key and App SID) | |
var slideService = new SlidesApi("API Key", "SID"); | |
// Defining the name of the input PowerPoint file | |
string inputFileName = "PresentationWithPics.pptx"; | |
// Uploading the PowerPoint file to Aspose cloud storage | |
var uploadResult = slideService.UploadFile(inputFileName, new MemoryStream(File.ReadAllBytes(inputFileName))); | |
// Downloading all images from the PowerPoint presentation in a ZIP file | |
var stream_zip = slideService.DownloadImagesDefaultFormat(name: "PresentationWithPics.pptx"); | |
// Saving the ZIP file containing all extracted images to the local storage | |
using (var fileStream = new FileStream("AllImages.zip", FileMode.Create, FileAccess.Write)) | |
{ | |
stream_zip.CopyTo(fileStream); // Copying the downloaded ZIP stream to a file | |
} | |
// Downloading a single image (indexed as 1) from the PowerPoint presentation | |
var singleImage = slideService.DownloadImageDefaultFormat(name: "PresentationWithPics.pptx", index: 1); | |
// Saving the extracted single image as a PNG file to the local storage | |
using (var fileStream = new FileStream("singleImage.png", FileMode.Create, FileAccess.Write)) | |
{ | |
singleImage.CopyTo(fileStream); // Copying the image stream to the file | |
} | |
} | |
} | |
} |
Este código demonstra como extrair imagens do PowerPoint com API C# Low Code. O método DownloadImagesDefaultFormat() pega o nome do arquivo de apresentação e retorna um fluxo ZIP que é salvo no armazenamento local. Todos os arquivos no arquivo ZIP contêm o tipo de imagem padrão.
Este artigo nos ensinou a extração de imagens de slides do PowerPoint com interface C# REST. Para adicionar uma marca d’água em uma apresentação, consulte o artigo Adicionar marca d’água ao PPT com API REST C#.