How to Access & Extract Images from Presentation Shapes inside .NET Apps
This technical tip explains how .NET developers can extract images from presentation shapes inside their .NET applications. Images are added in slide background and shapes. Sometimes, it is required to extract the images added in the presentation shapes. The images are added in IPPImageCollection inside Presentation Document Object Model (DOM). This article covers the feature of accessing the images in presentation shape, extracting them from presentation collection and saving them in a file. In Aspose.Slides for .NET, images can be added to slide shape and slide background. The images are added in IPPImageCollection of the presentation. In this example we will traverse through each shape inside every slide of presentation and see if there is any image added in slide shape. If the image will be found for any shape, we will extract that and will save it in file. The following code snippet will serve the purpose.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//your code here...
// Code Snippet for Extracting images from presentation shapes
[C# Code Sample]
String path = @"D:\Aspose Data\";
//Accessing the presentation
Presentation pres = new Presentation(path + "ExtractImages.pptx");
Aspose.Slides.IPPImage img = null;
Aspose.Slides.IPPImage Backimg = null;
int slideIndex = 0;
String ImageType = "";
bool ifImageFound = false;
for (int i = 0; i < pres.Slides.Count; i++)
{
slideIndex++;
//Accessing the first slide
ISlide sl = pres.Slides[i];
System.Drawing.Imaging.ImageFormat Format = System.Drawing.Imaging.ImageFormat.Jpeg;
//Accessing the first slide Slide sl = pres.getSlideByPosition(i);
if (sl.Background.FillFormat.FillType == FillType.Picture)
{
//Getting the back picture
Backimg = sl.Background.FillFormat.PictureFillFormat.Picture.Image;
//Setting the desired picture format
ImageType = Backimg.ContentType;
ImageType = ImageType.Remove(0, ImageType.IndexOf("/") + 1);
Format = GetImageFormat(ImageType);
String ImagePath = path + "BackImage_";
Backimg.SystemImage.Save(ImagePath + "Slide_" + slideIndex.ToString() + "." + ImageType, Format);
}
else
{
if (sl.LayoutSlide.Background.FillFormat.FillType == FillType.Picture)
{
//Getting the back picture
Backimg = sl.LayoutSlide.Background.FillFormat.PictureFillFormat.Picture.Image;
//Setting the desired picture format
X
Url: http://www.aspose.com/docs/display/slidesnet/Extracting+Images+from+Presentation+shapes
Language: C# | User: Sheraz Khan | Created: Jul 1, 2015 | Tags: access images in presentation shape extract images from presentation extract images from PPT slide shape extract images from slide background Presentation Document Object Model .NET PowerPoint API PowerPoint .NET Component