Getting Bitmap from WebView generates OutOfMemory crash

后端 未结 2 1618
长情又很酷
长情又很酷 2021-02-19 11:18

I have a custom WebView and I want to get a bitmap of its content (offscreen included). I used this code, which I got from here:

 public static Bitm         


        
2条回答
  •  隐瞒了意图╮
    2021-02-19 11:33

    Okay, I've cracked this one meself. The problem indeed was in the fact that the function returned the Bitmap waay before the zooming out procedure was over, so I had to delay it.

    I incorporated

    Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    //bulk of my code
                }
            }, 1000);
    

    which forced to change the structure of the function from public Bitmap to public void. Here's directly related thread. Despite some minor tweaks I still need to fix, the approach works like a charm

提交回复
热议问题