0

I have a byte array of a JPEG photo created as below.

        import java.sql.Blob;

        byte[] blobAsBytes = null;
        blobLength = (int) blob.length();
        blobAsBytes = blob.getBytes(1, blobLength);
        //Some operation to make the byte array size 20kb
        return blobAsBytes;

I need to return this byte array to a service which accepts Oracle long raw type and it works fine.

As this needs to be transferred through network, byte array returned by method has to be less than 20kb.

How can I make the byte array small in size, and send without any data loss, so it can be restored as a photo?

halfer
  • 19,824
  • 17
  • 99
  • 186
Nazneen
  • 789
  • 3
  • 12
  • 23
  • 1
    If usual compression algorithms don't work (likely to happen as most image formats are already compressed) you are out of luck. You can't work against information theory. – Henry Sep 16 '18 at 15:04
  • Could it be possible to make it to buffered image then reduce size and try converting back to byte array ? – Nazneen Sep 16 '18 at 15:10
  • Sure, if you are allowed to make the image smaller, its encoding is also smaller. But this would definitely change the image. – Henry Sep 16 '18 at 15:13
  • What image format is being used for the source `blob`? – RaffleBuffle Sep 16 '18 at 16:00
  • It has to be 'jpg'. But is it possible to achieve this with any format (just to know) ? – Nazneen Sep 16 '18 at 16:23
  • This thread helped me to get this done. https://stackoverflow.com/questions/12879540/image-resizing-in-java-to-reduce-image-size – Nazneen Sep 25 '18 at 08:19

0 Answers0