[英]How do I take a picture and then set activity background to that picture?
I'm trying to take a picture with the camera Intent and then immediately set the activity background to that image. 我正在尝试使用相机Intent拍照,然后立即将活动背景设置为该图像。
@SuppressWarnings("deprecation")
public void TakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = SavePicture();
} catch (IOException ex) {
return;
}
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, 1);
RelativeLayout rl = (RelativeLayout)findViewById(R.id.activity_layout);
Bitmap bitmap = BitmapFactory.decodeFile(photoFile.getAbsolutePath());
Drawable dr = new BitmapDrawable(bitmap);
rl.setBackgroundDrawable(dr);
}
}
}
Just looking at my code, it doesn't look correct. 仅查看我的代码,它看起来不正确。 Too much conversions from classes.
类转化过多。
How would I go about doing this? 我将如何去做呢?
Check similar StackOverflow solution on that issue. 在该问题上检查类似的StackOverflow解决方案。 I think you are looking for a complete solution on this issue.
我认为您正在寻找有关此问题的完整解决方案。 If so, this article would be good one for you:
如果是这样,这篇文章对您将是一件好事:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.