Add abilty for slides and note to extract image as byte array and save as different type byte array

HI i would like to add to slides and note, the ability i have in word and cell or pdf to extract image as a byte array and replace it with png image byte array

example for pdf

for (com.aspose.pdf.ImageFragment image : pdfDoc.getPages().get_Item(1).getResources().getImages()) {
    // Extract the image as a byte array
    ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
    image.save(imageStream, ImageFormat.getPng());

    // Replace the original image with the PNG image
    com.aspose.pdf.Image newImage = new com.aspose.pdf.Image();
    newImage.setImageStream(new ByteArrayInputStream(imageStream.toByteArray()));

    // Get the position and size of the original image
    Rectangle rect = image.getRectangle();
    float x = rect.getLLX();
    float y = rect.getLLY();
    float width = rect.getWidth();
    float height = rect.getHeight();

    // Replace the original image with the new PNG image
    pdfDoc.getPages().get_Item(1).getContents().replaceWithNewImage(counter, x, y, width, height, newImage);

@paveln1234,

We will look into your requirements regarding OneNote document and get back to you.

Regarding your reqiurements for Aspose.Slides, please post your queries in Aspose.Slides forum.

@paveln1234,

You can extract image bytes array using the Image.getBytes() property and then save to different type by yourselves. See the document with example code for your reference.

@paveln1234,
Aspose.Slides has the ability to get an image as a byte array and replace it with another image byte array.

Suppose a presentation has an image (the first shape) on the first slide:

Presentation presentation = new Presentation("example.pptx");
ISlide slide = presentation.getSlides().get_Item(0);
IPictureFrame pictureFrame = (IPictureFrame)slide.getShapes().get_Item(0);

IPPImage ppImage = pictureFrame.getPictureFormat().getPicture().getImage();

You can retrieve the image as a byte array like this:

byte[] imageData = ppImage.getBinaryData();
String imageType = ppImage.getContentType();

and replace the image with another one as follows:

byte[] newImageData = Files.readAllBytes(Paths.get("NewImage.png"));
ppImage.replaceImage(newImageData);

Documents: Replacing Images inside Presentation Image Collection
API Reference: IPPImage interface

Thank you very much for the slide answer but what about note do you going to add the option replace?

@paveln1234,

We already logged the following new ticket for it into our database:

  • NOTEJAVA-1182 - New API needed: Image.replace(input: anyformat, output: anyformat) to replace an image in a OneNote page with a new image

Once we have any new information available on your suggested feature/APIs, we will let you know.

hi,
any news?

@paveln1234,

We are sorry but your issue/required feature is not resolved/supported yet. We will check if we could provide an ETA on it. We will get back to you soon.

@paveln1234,

Could you please try using the following workaround solution for your requirements:
e.g.
Sample code:

String newImagePath = "";
String documentPath = "";
String outputDocumentPath = "";

Image newImage = new Image(newImagePath);

Document document = new Document(documentPath);

Image image = document.getChildNodes(Image.class).get(0);

CompositeNode<IPageChildNode> parent = (CompositeNode<IPageChildNode>) image.getParentNode();
int imagePosition = indexOf((Iterable) parent, image);

parent.removeChild(image);
parent.insertChild(imagePosition, newImage);

document.save(outputDocumentPath);

    public static int indexOf(Iterable<Node> source, Image v) {
        int i = 0;

        for (Node node : source) {
            try {
                Image imageNode = (Image) node;
                if (imageNode.equals(v)) {
                    return i;
                }
            } catch(ClassCastException e) {
                ++i;
            }
            ++i;
        }

        return -1;
    }

If this solution is not sufficient for you, please provide more details about the scenario in which the enhancement will be used. Additionally, please note that simply adding setBytes is not enough as there may be other parameters that could change, such as, FileName, FilePath, Height, and Width.

It would be helpful to know if there is a specific preference to update individual data in the existing image or if it would be more convenient to update all the image information as a whole.

We look forward to hearing back from you and understanding your requirements better.