Android View 截屏上下拼接

Android页面View截图(分享、保存相册)

Android View 截屏上下拼接  

Android View截屏长图拼接(RecyclerView)

Android View截屏长图拼接(NestedScrollView)

话不多说直接上代码

   /**
     * 高清截屏拼接图片(上下拼接)
     *
     * @param topView
     * @param bottomView
     * @return
     */
public static Bitmap mergeBitmapTopBottom(View topView, View bottomView) {
        int topW = topView.getWidth();
        int topH = topView.getHeight();
        int bottomW = bottomView.getWidth();
        int bottomH = bottomView.getHeight();

        Bitmap topBmp = Bitmap.createBitmap(topW, topH, Bitmap.Config.RGB_565);
        Canvas topCanvas = new Canvas(topBmp);
        /** 如果不设置canvas画布为白色,则生成透明 */
        topCanvas.drawColor(Color.WHITE);
        topView.layout(0, 0, topW, topH);
        topView.draw(topCanvas);

        Bitmap bottomBmp = Bitmap.createBitmap(bottomW, bottomH, Bitmap.Config.RGB_565);
        Canvas bottomCanvas = new Canvas(bottomBmp);
        /** 如果不设置canvas画布为白色,则生成透明 */
        bottomCanvas.drawColor(Color.WHITE);
        bottomView.layout(0, 0, bottomW, bottomH);
        bottomView.draw(bottomCanvas);

        Bitmap bitmap = Bitmap.createBitmap(topW, topH + bottomH, Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);

        Rect topRect = new Rect(0, 0, topW, topH);
        Rect bottomRect = new Rect(0, 0, bottomW, bottomH);

        Rect bottomDst = new Rect(0, topH, bottomW, topH + bottomH);

        canvas.drawBitmap(topBmp, topRect, topRect, null);
        canvas.drawBitmap(bottomBmp, bottomRect, bottomDst, null);
        topBmp.recycle();
        bottomBmp.recycle();
        topBmp = null;
        bottomBmp = null;
        return bitmap;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值