dllsndy 2016-07-21 06:28 采纳率: 0%
浏览 2014

android开发中三星的webview

public static Bitmap viewShot(final View view) {
if (view == null)
return null;
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
// if (view.getMeasuredWidth()<=0 || view.getMeasuredHeight()<=0) {
int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
view.measure(measureSpec, measureSpec);
// }

    if (view.getMeasuredWidth() <= 0 || view.getMeasuredHeight() <= 0) {
        L.e("ImageUtils.viewShot size error");
        return null;
    }
    Bitmap bm;
    try {
        bm = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
        L.e("view.getMeasuredWidth()" + view.getMeasuredWidth() + " view.getMeasuredHeight()" + view.getMeasuredHeight());
    } catch (OutOfMemoryError e) {
        System.gc();
        try {
            bm = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
        } catch (OutOfMemoryError ee) {
            L.e("ImageUtils.viewShot error", String.valueOf(ee));
            return null;
        }
    }
    Canvas bigCanvas = new Canvas(bm);
    Paint paint = new Paint();
    int iHeight = bm.getHeight();
    bigCanvas.drawBitmap(bm, 0, iHeight, paint);
    view.draw(bigCanvas);
    return bm;
}

/**
 * 保存图片到手机相册,并通知图库更新
 *
 * @param context
 * @param bmp     图片bitmap
 * @return 返回图片保存的路径,开发人员可以根据返回的路径在手机里面查看,部分手机发送通知图库并不会更新
 */
public static String saveImageToGallery(Context context, Bitmap bmp) {
    // 首先保存图片
    File appDir = new File(Environment.getExternalStorageDirectory(), Constants.DATA_DIR);
    if (!appDir.exists()) {
        appDir.mkdir();
    }
    String fileName = System.currentTimeMillis() + ".jpg";
    File file = new File(appDir, fileName);
    try {
        FileOutputStream fos = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // 最后通知图库更新
    String path = Environment.getExternalStorageDirectory() + Constants.DATA_DIR + fileName;
    context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path)));
    L.e(path);
    return Environment.getExternalStorageDirectory() + Constants.DATA_DIR + fileName;
}
    使用这两个方法对webview实现绘长图,图高度是长的 但是内容只有一屏,三星的才有这个问题,其他的还是正常的长图
  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!