彩票走势图

如何使用Aspose.Slides提取幻灯片中的图像

原创|其它|编辑:郝浩|2012-10-23 10:51:30.000|阅读 1374 次

概述:在幻灯片的背景和幻灯片页中,经常会添加有一些图像。有时,我们会提取这些背景和形状中的图像。 这篇文章介绍了如何使用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@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP