Reputation: 87
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);
Upvotes: 3
Views: 3374
Reputation: 1062
You might take a look at this: Savin bitmap files in Java
In the code, you can replace the file with a buffer, send it and load it on Android like you would from a file.
Upvotes: 0
Reputation: 22232
Convert Image to JPEG or PNG byte array and send that. InputStream can be decoded on Android.
Upvotes: 3