0

Javaで画面から画像をキャプチャするコードがあり、最終的にキャプチャされた画像をBufferedImageオブジェクトとして持っており、ImageIconにキャストできます

問題は、そのファイルを 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 を Bitmap drawable にキャストできないという例外が発生します。

4

1 に答える 1

0

片側に Java awt 部分があり、反対側に Android 部分があります。これはうまくいきません。png や jpg などの中間形式が必要です。画像をバイトに圧縮して送信し、反対側でデコードできます。
また、Androidではオブジェクトのシリアル化が非常に遅いです...

于 2013-05-01T15:08:59.610 に答える