1

I am getting jp2 in base64 format from server end. I am able to convert jpg to jp2 form ImageMagick library and send to server. They are able to convert it to jpg using Buffered Image and ImageIo . But I am not getting any idea to convert jp2 to jpg and render in Imageview. Hoping for any help. Thanks in advance.

Jeethendra
  • 29
  • 1
  • 6

3 Answers3

2

You probably solved it somehow already, but in case you're still looking for a solution, you can try the JP2 for Android library. (Disclaimer: I wrote the library.) It's based on OpenJPEG, like the DimaArts' response, but it has a bit nicer Java interface.

Add the following dependency to your build.gradle file:

implementation 'com.gemalto.jp2:jp2-android:1.0'

and use the following code to decode the JP2:

byte[] jp2Data = ...; //get the JP2 data from somewhere
Bitmap bmp = new JP2Decoder(jp2Data).decode();
imgView.setImageBitmap(bmp);
Michal Dvorak
  • 322
  • 1
  • 7
1

You can use OpenJpeg library for decode Jpeg2000. You can use compiled library https://github.com/DimaArts/OpenJpegAndroid. It contains an example of encode jpeg2000. Library supports PNG input and output formats for decoder and encoder. Try this:

OpenJPEGJavaDecoder decoder = new OpenJPEGJavaDecoder();
String[] params2 = new String[4];
params2[0] = "-i";
params2[1] = mInputPath; // path to jp2
params2[2] = "-o";
params2[3] = mOutputPath // path to png
decoder.decodeJ2KtoImage(params2);

if you are using JNI:

public int decodeJ2KtoImage(String[] parameters) {
    return internalDecodeJ2KtoImage(parameters);
}
DimaArts
  • 11
  • 3
-1

Try this code from https://stackoverflow.com/a/39103107/2760681

private static void convertImage(int randNum) throws IOException {
    try {
        File foundFile = new File("c:\\images\\" + randNum + ".jp2");   
        BufferedImage background = ImageIO.read(foundFile);
        ImageIO.write(background, "jpg", new File("c:\\images\\" + randNum + ".jpg"));
        System.out.println("jpg file is generated");
    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("No file " + randNum +".jp2 found");
    }

}
Jehad
  • 472
  • 2
  • 10
  • 24
  • Thanks for ur reply.. But BufferedImage and ImageIO is not supported in Android SDK. So, Please let me know for any alternatives – Jeethendra Jul 10 '17 at 09:21