android截图阴影,java – Android如何在截图中捕获阴影

试试这个.

CardView card = (CardView) findViewById(R.id.card);

现在只需将卡传递给captureScreenShot().它返回位图并保存该位图saveImage().

您可以传递任何视图,如RelativeLayout,LinearLayout等任何视图都可以传递给captureScreenShot().

// Function which capture Screenshot

public Bitmap captureScreenShot(View view) {

/*

* Creating a Bitmap of view with ARGB_4444.

* */

Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_4444);

Canvas canvas = new Canvas(bitmap);

Drawable backgroundDrawable = view.getBackground();

if (backgroundDrawable != null) {

backgroundDrawable.draw(canvas);

} else {

canvas.drawColor(Color.parseColor("#80000000"));

}

view.draw(canvas);

return bitmap;

}

// Function which Save image.

private void saveImage(Bitmap bitmap) {

File file = // Your Storage directory name + your filename

if (file == null) {

return;

}

try {

FileOutputStream fos = new FileOutputStream(file);

bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);

fos.close();

} catch (Exception e) {

e.printStackTrace();

}

}

最后像这样调用这个函数.

saveImage(captureScreenShot(card));

现在像这样设置你的图像.

File file = new File(“yourImageFilePath”);

if(file.exists())

{

yourImageView.setImageURI(Uri.fromFile(file));

}

注意:如果setImageURI()不起作用,那么您可以使用下面的代码.

File file = new File(“yourImageFilePath”);

if(file.exists())

{

Bitmap bitmap = BitmapFactory.decodeFile(file.toString());

yourImageView.setImageBitmap(bitmap);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值