Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Image to Bitmap form java application to android device

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);

like image 243
JackSie Avatar asked Jul 21 '26 16:07

JackSie


1 Answers

Convert Image to JPEG or PNG byte array and send that. InputStream can be decoded on Android.

like image 185
MaciejGórski Avatar answered Jul 24 '26 06:07

MaciejGórski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!