编写一段java代码解决ppt获取内部图片出现异常Keyframe fractions must be increasing: 1.0
时间: 2023-11-27 22:54:14 浏览: 122
这个异常通常在使用 Apache POI 库读取 ppt 文件时出现,原因是 ppt 文件中存在帧的时间轴不连续。解决方法是重新设置帧的时间轴。
以下是一段 Java 代码示例,演示如何处理这个异常:
```java
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.HSLFPictureData;
import org.apache.poi.util.IOUtils;
public class PPTImageExtractor {
public static void main(String[] args) throws IOException {
String pptFilePath = "path/to/ppt/file.ppt";
HSLFSlideShow ppt = new HSLFSlideShow(new FileInputStream(pptFilePath));
// 获取每张幻灯片中的所有图片
for (int i = 0; i < ppt.getSlides().size(); i++) {
HSLFPictureData[] pictures = ppt.getSlides().get(i).getPictureData();
for (int j = 0; j < pictures.length; j++) {
byte[] pictureData = pictures[j].getData();
IOUtils.writeFileToDisk(pictureData, "path/to/save/image.jpg");
}
}
ppt.close();
}
}
```
这段代码使用了 Apache POI 库来读取 ppt 文件,并遍历每张幻灯片中的所有图片,将图片数据保存到本地文件中。
如果出现异常 `Keyframe fractions must be increasing: 1.0`,可以尝试在读取 ppt 文件时添加以下代码:
```java
System.setProperty("org.apache.poi.hwmf.draw.path.limit", "1000000");
```
这行代码可以解决一些 ppt 文件读取时出现的问题。
阅读全文
相关推荐

















