Artikel ini memandu tentang cara mengekstrak gambar dari PowerPoint dengan C# REST API. Anda akan belajar mengambil gambar di PowerPoint secara otomatis dengan Antarmuka C# REST menggunakan SDK cloud berbasis .NET. Ini akan membagikan detail untuk mengekstrak semua gambar atau mengambil gambar yang dipilih dari presentasi.
Prasyarat
Unduh Aspose.Slides Cloud SDK for Dotnet to retrieve images from the presentation
Siapkan proyek C# dengan SDK di atas untuk mengekstraksi gambar
Langkah-langkah Mengekstrak Foto PowerPoint dengan C# REST API
- Inisialisasi objek SlidesApi untuk mengekstrak gambar menggunakan ID Klien dan rahasia
- Unggah file PowerPoint dengan gambar ke penyimpanan cloud Aspose
- Download semua gambar dari presentasi PowerPoint dalam file ZIP menggunakan metode DownloadImagesDefaultFormat()
- Simpan file ZIP yang berisi semua gambar yang diekstraksi ke penyimpanan lokal
- Unduh satu gambar dari presentasi PowerPoint
- Simpan gambar tunggal yang diekstraksi sebagai file PNG ke penyimpanan lokal
Langkah-langkah ini menjelaskan cara mengambil gambar presentasi PowerPoint dengan API berbasis C# .NET. Inisialisasi objek SlidesApi, unggah presentasi ke server, unduh semua gambar sebagai aliran ZIP dari respons API, dan simpan di disk. Gunakan metode DownloadImageDefaultFormat() untuk mengambil gambar yang diinginkan hanya dengan memberikan indeks gambar dalam presentasi.
Kode untuk Mengekstrak Gambar dalam Presentasi dengan C# RESTful Service
// 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 | |
} | |
} | |
} | |
} |
Kode ini menunjukkan cara mengekstrak gambar dari PowerPoint dengan C# Low Code API. Metode DownloadImagesDefaultFormat() mengambil nama file presentasi dan mengembalikan aliran ZIP yang disimpan di penyimpanan lokal. Semua file dalam file ZIP berisi tipe gambar default.
Artikel ini telah mengajari kita ekstraksi gambar slide PowerPoint dengan Antarmuka C# REST. Untuk menambahkan watermark pada presentasi, lihat artikel Tambahkan tanda air ke PPT dengan C# REST API.