Android: How to split Picture captured from webview in multiple images

别等时光非礼了梦想. 提交于 2020-01-01 18:13:49

问题


I have a webview and I capture the view like this

    Picture picture = m_browser.capturePicture();
    Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
                picture.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas( b );
    picture.draw( c );
    FileOutputStream fos = null;

    try {
        fos = new FileOutputStream("/sdcard/temp_1.jpg");
        //fos = openFileOutput("samsp_1.jpg", MODE_WORLD_WRITEABLE);
        if ( fos != null )
        {
            b.compress(Bitmap.CompressFormat.JPEG,90, fos);  
            fos.close();
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    }
}

Now if the loaded web site is long, for eg. times.com then this image is also too big.

I want to split this image in multiple images and with out reducing the quality.

I would like to get these images in the highest quality possible.

Pls. help Thanks


回答1:


It's a bit of a hack, but this will work on VERY long webpages without running out of memory. First, put your webview inside another layout (RelativeLayout rl). Size the RelativeLayout for the image size you want. Then call:

rl.draw(canvas);
// do something here to save your bitmap
webview.scrollby(0, rl.getHeight());

and repeat that till you're at the bottom of the page!




回答2:


Bitmap.createBitmap(source, x, y, width, height)

I allways use this code to cut the a large image to multiple images.

I can use it easy



来源:https://stackoverflow.com/questions/3465146/android-how-to-split-picture-captured-from-webview-in-multiple-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!