-1

(Please find the code snapshot here)-> 1. Hello so i have some tif and psd images that have clipping paths configured. what I want to do is, to extract them from java. so I use twelvemonkeys library that @haraldk has designed. but i am not able to get the paths. from the readPath() function. that is because, the imageinputstream that i get from the bufferedimage the buffer is all zeroes. i dont know why it happens. the buffer is valid untill ImageIO.createImageInputStream(source).(please refer the code snapshot in the link below). but after createimageinputstream(), the buffer has all zeroes. one more thing, this only works for jpg and tiffs. but for psd images i am not even getting the ByteArrayOutputStream as imageIO does not support psd images. can any one plz help me? thank you. the code snapshot is in the link below

  • Please provide code when asking questions. It would help other users to understand your problem and provide a good answer for you. – Augusto Jul 03 '20 at 12:00
  • yes Augusto, i have added the code snapshot in the question. thank you. – Durgaram Borkar Jul 06 '20 at 04:00
  • Sorry about the downvote... You should always include any *relevant* code in the question, as text. Using an image just makes it very hard to reproduce your problem. Also, make sure your code is self-contained. Using a main method or unit test is preferred! :-) – Harald K Jul 07 '20 at 19:07

1 Answers1

0

I have no idea what all that code in your screenshot does, as it is incomplete, but: You need to create the ImageInputStream from the original file contents. It's (IMO) quite straightforward. :-)

Either, read the image with the path applied:

try (ImageInputStream stream = ImageIO.createImageInputStream(new File("image_with_path.jpg")) {
    BufferedImage image = Paths.readClipped(stream);

    // Do something with the clipped image...
}

Or read the image and path separately (this is basically what readClipped(stream) does:

try (ImageInputStream stream = ImageIO.createImageInputStream(new File("image_with_path.jpg")) {
    Shape clip = Paths.readPath(stream);
    stream.seek(0);
    BufferedImage image = ImageIO.read(stream);

    if (clip != null) {
        image = Paths.applyClippingPath(clip, image);
    }

    // Do something with the clipped image...
}

I think your code does not work because you first read the image (using some non-disclosed code), then write only the pixel data to a temporary stream, and try to get the paths from there. But there are no path information in the BufferedImage, so the path information is "lost" in this operation. Again, you need to get it from the original file contents.

Harald K
  • 26,314
  • 7
  • 65
  • 111