开发者

Fast display Bitmaps in Android

开发者 https://www.devze.com 2023-02-18 16:50 出处:网络
I wrote a little client-server application, that transfers Bitmaps over tcp. The server part works like a charm, but on the client side I\'m not sure how to display the received bitmaps. The client ba

I wrote a little client-server application, that transfers Bitmaps over tcp. The server part works like a charm, but on the client side I'm not sure how to display the received bitmaps. The client back开发者_JAVA百科end calls everytime a new picture is received a method in the activity, that should update and display the bitmap...up to 25 fps. What is the nicest solution?

I wrote an own view, but calling setContentView doesn't work for me, it missed displaying the bitmaps and the screen stays black, until the server closes, then one image is displayed correctly. I even tried something like this:

this.image = (ImageView) findViewById(R.id.imageView1);

and

    public void setImage(BufferedImage bufImage) {
    if (bufImage.hasBitmap()) {
        this.image.setImageBitmap(bufImage.getBitmap());
    }
}

(I wrote an own BufferedImage class, that holds correct Bitmaps)

Even with image.invalidate() nothing happens until the server closes the connection...


Sounds like maybe you're doing your network IO on the user interface thread. What happens in that case is that nothing in the UI get updated till the network operations are complete. If so what you need to do is create a thread to run the server IO, and have it call back to the UI thread with frames to display. Here's some general info about how threading and the user interface interact that should help if so:

http://developer.android.com/resources/articles/painless-threading.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号