I wrote a java application that creates some Images from a webcam and their format is java.awt.Image. I want to show those images on my Android device however, ADK doesn't include java.awt.
I want to convert it in the java application and show the image in Android by converting the Image to a Bitmap then transfer it to Android via a socket connection.
I Googled for a solution and some examples used BitmapFactory.decodeResource but it seems to be of no use in this situation.
///// 2012/4/15 added////////////
I use this ,but don't works , is there any wrong with it
/////OUTPUT/////
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(image, "png", baos);
} catch (IOException e) {e.printStackTrace();}
byte[] data = baos.toByteArray();
int len =data.length;
oos.writeInt(len);
oos.flush();
oos.write(data);
oos.flush();
/////INPUT/////
int size =dis.readInt();
byte []data=new byte[size];
dis.read(data);
image = BitmapFactory.decodeByteArray(data, 0, data.length);
Convert Image to JPEG or PNG byte array and send that. InputStream can be decoded on Android.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With