0

I have a Web Service that takes a photo through a POST statement and returns a modified copy of that photo back. We are making changes to the way it processes the photo, and I want to verify that the photo at least has different properties coming back than it did before our changes went into effect.

The photo is being returned as a byte stream inside one of the fields of a JSON object. I can analyze the JSON object pretty easily, but I'm trying to figure out how to get the byte stream into an Java image object so that I can get its dimensions.

John Chesshir
  • 590
  • 5
  • 20

2 Answers2

1

Possible duplicate of this question

... I'm trying to figure out how to get the byte stream into an Java image object so that i can get its dimensions.

I'd suggest using a BufferedImage in the following format/snippet. Note: I load my image in from disk for the example and use try-with-resources (which you may revert to 1.6-prior if needed).

    String fp = "C:\\Users\\Nick\\Desktop\\test.png";
    try (FileInputStream fis = new FileInputStream(new File(fp));
            BufferedInputStream bis = new BufferedInputStream(fis)) {
        BufferedImage img = ImageIO.read(bis);
        final int w = img.getWidth(null);
        final int h = img.getHeight(null);
    }
Community
  • 1
  • 1
Nick Bell
  • 516
  • 3
  • 16
  • I like this mainly for the reference to the other post. That one is very informative with lots of different ways to get the data, some simple, some fast. – John Chesshir Oct 11 '16 at 21:36
0

You can use:

  1. OS Process Sampler and 3rd-party tool like ImageMagick
  2. JSR223 Test Elements, to wit

Depending on what parameters you need to compare you can use ImageIO API (out of the box, bundled with JDK), Commons Imaging, ImageJ and so on.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133