如何使用Aspose.Slides提取幻灯片中的图像
发布网友
发布时间:2022-04-28 16:12
我来回答
共1个回答
热心网友
时间:2022-06-19 15:47
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);
}
}