簡體   English   中英

從 Aspose.slide java 替換圖像時出錯

[英]Error in replacing image from 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

對於您的以下問題:

問題 1:我創建了 pptx,並且在一張幻燈片中有 2 個相同的圖像。 當我試圖替換一個圖像時,圖像都被替換並且它拋出了警告消息。

這不是問題。 實際上,演示中的圖像實際上是添加到演示圖像集合中的。 因此,如果您添加兩個相似的圖像,API 將只保留其中一個並避免重復。 因此,如果兩個或多個形狀共享相同的圖像,那么在后端,圖像集合中有單個圖像供它們使用。 此外,當您將圖像添加到演示文稿時,您首先將圖像添加到 ImageCollection,然后根據需要將該添加的圖像關聯到一個或多個形狀。 因此,這不是問題,如果您想采用這種方法,那么您的圖像必須略有不同。 否則,Aspose.Slides 會將它們視為相似圖像。 因此,當您更改圖像時,與該圖像關聯的所有形狀都將替換圖像。 這不是問題。

問題 2:我創建了 pptx 並且它有 2 個圖像,一段時間后我在第 2 個位置添加了第 3 個圖像,我正在嘗試替換它。 它正在替換第三個位置的圖像。

我使用 Aspose.Slides for Java 19.7 處理了您共享的源文件,但無法觀察到問題。 我還與您分享了我生成的結果以供您參考。

我在 Aspose 擔任支持開發人員/傳播者。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM