java - 从 Aspose.slide java 替换图像时出错
问题描述
错误 :-
警告:发生了非法反射访问操作警告:com.aspose.slides.ms.core.System.Drawing.imagecodecs.jpeg.oracle.OracleJpegImageReader 的非法反射访问(文件:/home/prdxn70/.m2/repository/com /aspose/aspose-slides/19.7/aspose-slides-19.7-jdk16.jar) 到字段 com.sun.imageio.plugins.jpeg.JPEGImageReader.colorSpaceCode 警告:请考虑将此报告给 com.aspose.slides 的维护者。 ms.core.System.Drawing.imagecodecs.jpeg.oracle.OracleJpegImageReader 警告:使用 --illegal-access=warn 启用对进一步非法反射访问操作的警告 警告:所有非法访问操作将在未来版本中被拒绝
问题 1:我创建了 pptx,并且在一张幻灯片中有 2 个相同的图像。当我试图替换一个图像时,图像都被替换并且它抛出了警告消息。
问题 2:我创建了 pptx 并且它有 2 个图像,一段时间后我在第 2 个位置添加了第 3 个图像,我正在尝试替换它。它正在替换第三个位置的图像。
我正在尝试下面的代码..
public static void main(String[] args) throws FileNotFoundException {
String dataDir = "/home/prdxn70/eclipse-workspace/ppt/src/main/resources/com/demo/ppt/App/";
try {
//Instantiate the presentation
Presentation presentation = new Presentation(dataDir + "two.pptx");
//Read image from source
File file = new File(dataDir + "img2.png");
byte[]data = new byte[(int) file.length()];
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
inputStream.read(data);
// Instantiate SlideCollection calss ISlideCollection slds =
presentation.getSlides(); // Get the first slide ISlide sld = (ISlide)
presentation.getSlides().get_Item(0);
} finally {
inputStream.close();
}
//Code for replace Image
IPPImage oldImage = presentation.getImages().get_Item(0);
System.out.println(oldImage);
oldImage.replaceImage(data);
//Save the presentation
presentation.save(dataDir + "HelloWorld.pptx", SaveFormat.Pptx);
} catch (Exception e) {
System.out.println(e);
}
pptx链接:-
https://drive.google.com/open?id=15NSxAHi311q8Hg3lJn4i8HrOkYOg_THT
解决方案
@Saquib S,
对于您的以下问题:
问题 1:我创建了 pptx,并且在一张幻灯片中有 2 个相同的图像。当我试图替换一个图像时,图像都被替换并且它抛出了警告消息。
这不是问题。实际上,演示中的图像实际上是添加到演示图像集合中的。因此,如果您添加两个相似的图像,API 将只保留其中一个并避免重复。因此,如果两个或多个形状共享相同的图像,那么在后端,图像集合中有单个图像供它们使用。此外,当您将图像添加到演示文稿时,您首先将图像添加到 ImageCollection,然后根据需要将该添加的图像关联到一个或多个形状。因此,这不是问题,如果您想采用这种方法,那么您的图像必须略有不同。否则,Aspose.Slides 会将它们视为相似图像。因此,当您更改图像时,与该图像关联的所有形状都将替换图像。这不是问题。
问题 2:我创建了 pptx 并且它有 2 个图像,一段时间后我在第 2 个位置添加了第 3 个图像,我正在尝试替换它。它正在替换第三个位置的图像。
我使用 Aspose.Slides for Java 19.7 处理了您共享的源文件,但无法观察到问题。我还与您分享了我生成的结果以供您参考。
我在 Aspose 担任支持开发人员/传播者。
推荐阅读
- javascript - 如何使用 fetchjsonp 中止信号?fetchjsonp(网址,{信号})?
- ms-word - 有没有办法创建不是任务窗格的 Microsoft Word 加载项?
- python - flask中的send_static_file如何查找静态文件?
- python - scipy.optimize.minimize - slsqp - hessian 矩阵
- javascript - 在javascript中发出http请求时出现400错误
- html - fabricJS:缩放画布视图
- javascript - JavaScript 函数读取参数的方式与我预期的不同
- ajax - 渲染特定模板/ AJAX 请求时,Cakephp 3 查看 App 控制器中设置的变量不可用
- java - 每次 Java 编译警告
- c - 根据输入大小创建数组