可能重复:
how to extract all images from a .ppt file using Android with help of Apache poi?
我正在为Android的ppt viewer工作。我已经在Apache POI API的帮助下从ppt中提取了所有文本但无法在ppt文件中提取图像。我很乐意知道结果....我的代码在这里 link
答案 0 :(得分:2)
检查以下代码以读取PPTX文件中的所有图像:
SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt"));
//extract all pictures contained in the presentation
PictureData[] pdata = ppt.getPictureData();
for (int i = 0; i < pdata.length; i++){
PictureData pict = pdata[i];
// picture data
byte[] data = pict.getData();
int type = pict.getType();
String ext;
switch (type){
case Picture.JPEG: ext=".jpg"; break;
case Picture.PNG: ext=".png"; break;
case Picture.WMF: ext=".wmf"; break;
case Picture.EMF: ext=".emf"; break;
case Picture.PICT: ext=".pict"; break;
default: continue;
}
FileOutputStream out = new FileOutputStream("pict_"+i + ext);
out.write(data);
out.close();
}