tags:

views:

53

answers:

3

How to convert image to byte array in J2ME ??

A: 
  • Did you try toString? (don't know if that works, just guessing)
  • You can call getRGB in loop to get all the pixel values.
hlynur
Neither of these work in J2ME.
funkybro
Neither of these work for mee too.
success_anil
Written following code for getting byte [] out of image ..byte[] capturedImageData = imageOnScreen.toString().getBytes();Is it right ?
success_anil
+1  A: 

You can't get the original (probably compressed) image back. But you can use [Image.getRGB()][1] to retrieve the RGB data; this can then be stored somewhere, and the image reconstructed later. This will take up more space than the original .png (or whatever format it was); you'll need to compress it yourself if that is unacceptable.

[1]: http://download-llnw.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Image.html#getRGB(int[], int, int, int, int, int, int)

funkybro
:D:D:D Brilliant! You've downrated my answer first, and then copied second part of it as your proposal, and now you're waiting for UP-votes.
hlynur
?? Your link points to a method using Image.getPixel() which isn't available in J2ME.
funkybro
OK, now read the sentence again ...and again if it still didn't help.
hlynur
A: 

Use this function getRGB, it will return the byte array!

getRGB(rgbs, 0, image.getWidth() , 0, 0, image.getWidth(), image.getHeight());

Azlam