Cropping an image then converting to a Base64 string on J2ME: NullPointerException

43 views
Skip to first unread message

cubiq1

unread,
Aug 26, 2014, 7:37:09 AM8/26/14
to codenameone...@googlegroups.com
Hi,

I'm trying to crop a captured image (using Image.subImage) before uploading it as a Base64 string.

On J2ME I'm having issues converting this cropped image to Base64. The following code results in a NullPointerException:

    // Method 1
   
ByteArrayOutputStream baos=new ByteArrayOutputStream();
   
ImageIO.getImageIO().save(subImage, baos, ImageIO.FORMAT_JPEG, 1);
   
byte[] b = baos.toByteArray();
    imageBase64
= Base64.encodeNoNewline(b);

So I tried this, as Image.IO isn't supported on J2ME, but it didn't either work:

    // Method 2
   
EncodedImage encImg = EncodedImage.createFromImage(subImage, true);
    imageBase64
= Base64.encodeNoNewline(encImg.getImageData());

Is there anyway to do this on J2ME?

Thanks

Shai Almog

unread,
Aug 26, 2014, 10:13:59 AM8/26/14
to codenameone...@googlegroups.com
Hi,
creating an encoded image uses image IO internally so this won't work on J2ME either.
There is no way to do something like that in J2ME. You would have to go around either via the ARGB data or by sending the full image with cropping instructions to the server.

cubiq1

unread,
Aug 26, 2014, 1:14:27 PM8/26/14
to codenameone...@googlegroups.com
Hi, thanks. I'll have to do cropping on the server.
Reply all
Reply to author
Forward
0 new messages