公司功能需求,所以将此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传递,再取出来
在进行操作.应该也是可行的