简体   繁体   中英

Android - ImageView flickering by changing the Image (Bitmap) on it

I have got a Image (Bitmap) on a ImageView, without flickering. When I change something with setPixel(x, y, COLOR_VALUE) , so some Pixels are changed on the ImageView, it begins to flicker, where I changed the Pixels.

public class Drawer extends ImageView {

private Bitmap someBitmap;

public void doSomeDrawing() {
    for (int i = 0; i < 100; i = i + 2) {
        someBitmap.setPixel(x, y, COLOR_VALUE);
    }
    setOnDraw();
}

public void setOnDraw() {
   this.setImageBitmap(someBitmap);
}

Try getting a copy of your bitmap and draw on it. Then recycle your old bitmap.

The problem here might also be that setting the pixel takes time and if you do this on the UI Thread, it will slow down your app and may cause flickering too. How much time does doSomething take ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM