diff --git a/en/net/developer-guide/presentation-content/manage-media-files/image/_index.md b/en/net/developer-guide/presentation-content/manage-media-files/image/_index.md index 33a838d3a1..9018297ea1 100644 --- a/en/net/developer-guide/presentation-content/manage-media-files/image/_index.md +++ b/en/net/developer-guide/presentation-content/manage-media-files/image/_index.md @@ -210,8 +210,43 @@ using (Workbook book = new Workbook(dataDir + "chart.xlsx")) } ``` +## **Replacing Images in the Image Collection** + +Aspose.Slides lets you replace images stored in a presentation’s image collection (including those used by slide shapes). This section shows several approaches to updating images in the collection. The API provides straightforward methods to replace an image using raw byte data, an [IImage](https://reference.aspose.com/slides/net/aspose.slides/iimage/) instance, or another image that already exists in the collection. + +Please follow the steps below: + +1. Load the presentation file that contains images using the [Presentation](https://reference.aspose.com/slides/net/aspose.slides/presentation/) class. +1. Load a new image from a file into a byte array. +1. Replace the target image with the new image using the byte array. +1. In the second approach, load the image into an [IImage](https://reference.aspose.com/slides/net/aspose.slides/iimage/) object and replace the target image with that object. +1. In the third approach, replace the target image with an image that already exists in the presentation’s image collection. +1. Write the modified presentation as a PPTX file. + +```cs +// Instantiate the Presentation class that represents a presentation file. +using Presentation presentation = new Presentation("sample.pptx"); + +// The first way. +byte[] data = File.ReadAllBytes("image0.jpeg"); +IPPImage oldImage = presentation.Images[0]; +oldImage.ReplaceImage(data); + +// The second way. +using IImage newImage = Images.FromFile("image1.png"); +oldImage = presentation.Images[1]; +oldImage.ReplaceImage(newImage); + +// The third way. +oldImage = presentation.Images[2]; +oldImage.ReplaceImage(presentation.Images[3]); + +// Save the presentation to a file. +presentation.Save("output.pptx", SaveFormat.Pptx); +``` + {{% alert title="Info" color="info" %}} Using Aspose FREE [Text to GIF](https://products.aspose.app/slides/text-to-gif) converter, you can easily animate texts, create GIFs from texts, etc. -{{% /alert %}} \ No newline at end of file +{{% /alert %}} diff --git a/en/net/developer-guide/technical-articles/replacing-images-inside-presentation-image-collection/_index.md b/en/net/developer-guide/technical-articles/replacing-images-inside-presentation-image-collection/_index.md deleted file mode 100644 index 26497a10c3..0000000000 --- a/en/net/developer-guide/technical-articles/replacing-images-inside-presentation-image-collection/_index.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: Replacing Images inside Presentation Image Collection -type: docs -weight: 110 -url: /net/replacing-images-inside-presentation-image-collection/ ---- - -{{% alert color="primary" %}} - -Aspose.Slides for .NET makes it possible to replace the images added in slide shapes. This article explains how to replace the image added in presentation image collection using different approaches. - -{{% /alert %}} -## **Replacing Image inside Presentation Image Collection** -Aspose.Slides for .NET provides a simple API methods for replacing the images inside presentation image collection. Please follow the steps below: - -1. Load the presentation file with image inside it using [Presentation](https://reference.aspose.com/slides/net/aspose.slides/presentation) class. -1. Load an image from file in byte array. -1. Replace the target image with new image in byte array -1. In second approach load the image in Image object and replace the target image with loaded image. -1. In third approach replace the image with already added image in presentation image collection. -1. Write the modified presentation as a PPTX file. - -```c# -//Instantiate the presentation -using Presentation presentation = new Presentation("presentation.pptx"); - -//the first way -byte[] data = File.ReadAllBytes("image0.jpeg"); -IPPImage oldImage = presentation.Images[0]; -oldImage.ReplaceImage(data); - -//the second way -using IImage newImage = Images.FromFile("image1.png"); -oldImage = presentation.Images[1]; -oldImage.ReplaceImage(newImage); - -//the third way -oldImage = presentation.Images[2]; -oldImage.ReplaceImage(presentation.Images[3]); - -//Save the presentation -presentation.Save("c:\\Presentations\\TestSmart.pptx", SaveFormat.Pptx); -``` -