我的代码从屏幕在Java中,我有最后拍摄的图像作为BufferedImage对象可以投它的ImageIcon错误从Java发送拍摄的图像到Android
的问题发送该文件时捕获图像到android不能读取它作为位图绘制。任何人都有答案?
代码发送(JAVA)
BufferedImage image = robot.createScreenCapture(rectangle);
ImageIcon imageIcon = new ImageIcon(image);
//Send captured screen to the server
try {
System.out.println("before sending image");
oos.writeObject(imageIcon);
oos.reset(); //Clear ObjectOutputStream cache
System.out.println("New screenshot sent");
} catch (IOException ex) {
ex.printStackTrace();
}
Android的接收器部分
Thread t= new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
client= sc.accept();
is = client.getInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BitmapDrawable imageIcon = null;
try {
ois = new ObjectInputStream(is);
imageIcon = (BitmapDrawable) ois.readObject();
//Drawable d = Drawable.createFromStream(is, null);
IV.setImageDrawable(imageIcon);
} catch (OptionalDataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("New image recieved");
}
}
我得到它的异常不能施放的ImageIcon或位图绘制数据的BufferedImage。
是的,但Android中没有ImageIcon类,我不知道该转换! – MSaudi 2013-04-28 15:43:40
也许最好开始一个新问题:“我如何将ImageIcon转换为Android中的BitmapDrawable?”。关于序列化和投射的东西确实会减损这个主要问题。不幸的是,我主要是一个Java开发人员,并且不太了解Android来帮助你。 :( – 2013-04-28 15:52:18