Android截取所需要的activity并上下拼接其他图片

公司功能需求,所以将此Demo记录下来

先来看看效果图


左侧为上一个activity  ,右侧为跳转后的activity,将上一个activity截屏,然后与其他图片进行拼接,同时注意,屏幕大小,进行图片调整

代码命名没有规范..见谅

前一个activity

public static Activity mActivity;

跳转后Activity

bt = (Button) findViewById(R.id.zzza);
zzz = (ImageView) findViewById(R.id.zzz);
bt.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        Bitmap mp = captureScreen(MainActivity.mActivity);    
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.share_bootom);
        float x = mp.getWidth() / (bmp.getWidth()*1.0f);   //  适配屏幕,获取拼接图片之间比例
        Toast.makeText(Main3Activity.this, "" +x+"   "+(int) (bmp.getWidth() * x)+"    "+(int) (bmp.getHeight() * x), Toast.LENGTH_SHORT).show();
        bmp = Bitmap.createScaledBitmap(bmp, (int) (bmp.getWidth() * x), (int) (bmp.getHeight() * x), true);  //获取修改后的第二张图片
        zzz.setImageBitmap(mergeBitmap(mp, bmp));

    }
});
//截取目标activity的  屏幕
public static Bitmap captureScreen(Activity activity) {
    activity.getWindow().getDecorView().setDrawingCacheEnabled(true);
    Bitmap bmp=activity.getWindow().getDecorView().getDrawingCache();
    return bmp;
}
//将两个照片进行拼接
private Bitmap mergeBitmap(Bitmap firstBitmap, Bitmap secondBitmap) {

    Bitmap bitmap3 = Bitmap.createBitmap(firstBitmap.getWidth(), firstBitmap.getHeight()+secondBitmap.getHeight(), firstBitmap.getConfig());
    Canvas canvas = new Canvas(bitmap3);
    canvas.drawBitmap(firstBitmap, new Matrix(), null);
    canvas.drawBitmap(secondBitmap, 0,  firstBitmap.getHeight(), null);  //120、350为bitmap2写入点的x、y坐标
    return bitmap3;
}
这里利用activity进行截屏,  除此 我还有另一个思路,未进行实现,不过应该也是可以实现的

我们将前一个activity的屏幕先截屏,然后通过bundle传递,再取出来

在进行操作.应该也是可行的


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值