'Error in replacing image from Aspose.slide java

Error :-

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.aspose.slides.ms.core.System.Drawing.imagecodecs.jpeg.oracle.OracleJpegImageReader (file:/home/prdxn70/.m2/repository/com/aspose/aspose-slides/19.7/aspose-slides-19.7-jdk16.jar) to field com.sun.imageio.plugins.jpeg.JPEGImageReader.colorSpaceCode WARNING: Please consider reporting this to the maintainers of com.aspose.slides.ms.core.System.Drawing.imagecodecs.jpeg.oracle.OracleJpegImageReader WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release


Problem 1: I have created pptx and I am having 2 same image in one slide. as I am trying to replace one image both the image get replaced and it throws above WARNING message.

Problem 2: I have created pptx and it has 2 image after some time I have added 3rd image at the 2nd position and I am trying to replace it. It is replacing image at the 3rd position.

I am Trying Below code..

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);
    }

Link for pptx:-

https://drive.google.com/open?id=15NSxAHi311q8Hg3lJn4i8HrOkYOg_THT



Solution 1:[1]

For your following problem:

Problem 1: I have created pptx and I am having 2 same image in one slide. as I am trying to replace one image both the image get replaced and it throws above WARNING message.

This is not an issue. Actually, the images in presentation are in fact added in presentation image collection. So, if you add two similar images, the API keeps only one out of them and avoid duplicity. So, two or more shapes if share same image then on back end there is single image in Image collection for them. Also, when you add image to presentation, you first add image to ImageCollection and then you associate that added image to one or more shapes as desired. So, this is not an issue and if you want to have this approach then your images must be slightly differing. Otherwise, Aspose.Slides will treat them as similar image. So when you will change the image then all shapes associated with that image will have replaced image. Its not an issue.

Problem 2: I have created pptx and it has 2 image after some time I have added 3rd image at the 2nd position and I am trying to replace it. It is replacing image at the 3rd position.

I have worked with source file shared by you using Aspose.Slides for Java 19.7 and unable to observe issue. I have also shared my generated result with you for your kind reference.

I am working as Support developer/ Evangelist at Aspose.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wai Ha Lee