【问题标题】:Android saving webview to gallery, intermediate bitmap is too bigAndroid将webview保存到图库,中间位图太大
【发布时间】:2015-07-09 04:11:25
【问题描述】:

我正在尝试在 android 中编写一个方法来将整个 webview 保存为图像,如下所示:

    bitmap = Bitmap.createBitmap(webView.getWidth(),
        Math.round(webView.getContentHeight() * webView.getScale()), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    webView.draw(canvas);
    FileOutputStream out = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.JPEG, JPEG_COMPRESSION, out);

但是,位图太大(超过 100 MB)并且占用了太多内存。有谁知道保持低内存使用的更好方法? 问题是WebView很小,生成的JPEG文件很小,但中间的Bitmap很大,其他地方不用了。

【问题讨论】:

    标签: android webview bitmap android-webview android-bitmap


    【解决方案1】:

    设置 JPEG_COMPRESSION = 0-100,因为它是位图的 quality 参数,0 表示压缩为小尺寸,100 表示压缩为最大质量。

    您还可以使用设置位图高度和宽度 BitmapFactory.Options bop

    bop.outWidth

    bop.outHeight

    【讨论】:

    • JPEG 文件大小可以接受,但中间位图太大。我正在考虑将位图切成小块并逐块压缩,但我找不到任何方法将它们以 JPEG 形式连接在一起。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多