原創|其它|編輯:郝浩|2012-10-23 10:51:30.000|閱讀 1415 次
概述:在幻燈片的背景和幻燈片頁中,經常會添加有一些圖像。有時,我們會提取這些背景和形狀中的圖像。 這篇文章介紹了如何使用Aspose.Slides提取幻燈片中圖像的方法,并將之保存在一個文件夾中。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在幻燈片的背景和幻燈片頁中,經常會添加有一些圖像。有時,我們會提取這些背景和形狀中的圖像。 這篇文章介紹了如何使用Aspose.Slides提取幻燈片中圖像的方法,并將之保存在一個文件夾中。
在Aspose.Slides中,圖像可以被添加到幻燈片頁和幻燈片的背景中。在下面的示例中,我們將遍歷幻燈片中的每一頁看看是否添加有圖像。如果發現圖像,我們將進行提取,并將它保存在文件。
廢話不多說,上代碼:
[C#]
String path = @"..\..\..\"; //Accessing the presentation PresentationEx pres = new PresentationEx(path+"demo.pptx"); ImageEx img = null; int slideIndex = 0; for (int i = 0; i < pres.Slides.Count; i++) { slideIndex++; //Accessing the first slide SlideEx sl = pres.Slides[i]; System.Drawing.Imaging.ImageFormat Format = System.Drawing.Imaging.ImageFormat.Jpeg; for (int j = 0; j < sl.Shapes.Count; j++) { // Accessing the shape with picture Aspose.Slides.Pptx.ShapeEx sh = sl.Shapes[j]; if (sh is AutoShapeEx) { AutoShapeEx ashp = (AutoShapeEx)sh; if (ashp.FillFormat.FillType == FillTypeEx.Picture) { img = ashp.FillFormat.PictureFillFormat.Picture.Image; } } else if (sh is PictureFrameEx) { PictureFrameEx pf = (PictureFrameEx)sh; if (pf.FillFormat.FillType == FillTypeEx.Picture) { img = pf.PictureFormat.Picture.Image; } } String ImageType = img.ContentType; ImageType = ImageType.Remove(0, ImageType.IndexOf("/") + 1); // //Setting the desired picture format switch (ImageType) { case "jpeg": Format = System.Drawing.Imaging.ImageFormat.Jpeg; break; case "emf": Format = System.Drawing.Imaging.ImageFormat.Emf; break; case "bmp": Format = System.Drawing.Imaging.ImageFormat.Bmp; break; case "png": Format = System.Drawing.Imaging.ImageFormat.Png; break; case "wmf": Format = System.Drawing.Imaging.ImageFormat.Wmf; break; case "gif": Format = System.Drawing.Imaging.ImageFormat.Gif; break; } // String ImagePath = path+"Image_"; img.Image.Save(ImagePath + "Slide_" + slideIndex.ToString() + "." + ImageType, Format); } }
[Visual Basic]
Dim path As String = "..\..\..\" 'Accessing the presentation Dim pres As New PresentationEx(path & "demo.pptx") Dim img As ImageEx = Nothing Dim slideIndex As Integer = 0 For i As Integer = 0 To pres.Slides.Count - 1 slideIndex += 1 'Accessing the first slide Dim sl As SlideEx = pres.Slides(i) Dim Format As System.Drawing.Imaging.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg For j As Integer = 0 To sl.Shapes.Count - 1 ' Accessing the shape with picture Dim sh As Aspose.Slides.Pptx.ShapeEx = sl.Shapes(j) If TypeOf sh Is AutoShapeEx Then Dim ashp As AutoShapeEx = CType(sh, AutoShapeEx) If ashp.FillFormat.FillType = FillTypeEx.Picture Then img = ashp.FillFormat.PictureFillFormat.Picture.Image End If ElseIf TypeOf sh Is PictureFrameEx Then Dim pf As PictureFrameEx = CType(sh, PictureFrameEx) If pf.FillFormat.FillType = FillTypeEx.Picture Then img = pf.PictureFormat.Picture.Image End If End If Dim ImageType As String = img.ContentType ImageType = ImageType.Remove(0, ImageType.IndexOf("/") + 1) ' 'Setting the desired picture format Select Case ImageType Case "jpeg" Format = System.Drawing.Imaging.ImageFormat.Jpeg Case "emf" Format = System.Drawing.Imaging.ImageFormat.Emf Case "bmp" Format = System.Drawing.Imaging.ImageFormat.Bmp Case "png" Format = System.Drawing.Imaging.ImageFormat.Png Case "wmf" Format = System.Drawing.Imaging.ImageFormat.Wmf Case "gif" Format = System.Drawing.Imaging.ImageFormat.Gif End Select ' Dim ImagePath As String = path & "Image_" img.Image.Save(ImagePath & "Slide_" & slideIndex.ToString() & "." & ImageType, Format) Next j Next i
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網