我的代碼在Java中捕獲圖像從屏幕上,我有最後拍攝的圖像作爲BufferedImage對象,並且可以將其丟如何將ImageIcon轉換爲Android中的BitmapDrawable?
的問題發送該文件到Android無法讀取它作爲位圖繪製時到的ImageIcon 。任何人都有答案?
代碼發送(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。
爲什麼不使用Bitmap API而不是BufferedImage和ImageIcon? – DeeV 2013-05-01 15:09:44
你爲什麼從兩個不同的賬戶問同樣的問題(同一問題主體)? – tilpner 2013-05-01 15:37:01
,因爲它是我們正在處理的同一個項目 – 2013-05-01 16:41:51