我有一个打开相机的应用,它以uri字符串形式保存照片,我 并在imagebutton中显示它,我在教程中看到了,所以我真的不知道它是如何工作的
首先,当用户单击名为PlayerChoose1Btn的图像按钮时,我会弹出一个窗口,以便用户允许该应用程序使用相机并根据需要保存它,但我认为向您展示此代码并不重要。用户接受一种打开相机的方法,这是这里执行的方法
private void openCamera() {
Contentvalues values = new Contentvalues();
values.put(MediaStore.Images.Media.TITLE,"New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION,"From theCamera");
Player1Image =
getcontentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
//Camera intent
Intent cameraIntent = new Intent(MediaStore.actION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,Player1Image);
startactivityForResult(cameraIntent,IMAGE_CAPTURE_CODE);
}
Player1Image是Uri字符串。然后,我还有另一种在拍照时调用的方法
@Override
protected void onactivityResult(int requestCode,int resultCode,Intent
data) {
//called when image was captured from camera
super.onactivityResult(requestCode,resultCode,data);
if (resultCode == RESULT_OK) {
//set the image captured to our ImageView
PlayerChoose1Btn.setImageURI(Player1Image);
}
PlayerChoose1Btn是我想要显示照片的ImageButton
在此处绘制图形:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#ac7339"/>
<corners android:radius="50dp"/>
<stroke android:color="#ac7339"
android:width="5dp"/>
</shape>
</item>
</layer-list>
我希望当用户决定将图片保存在上面的可绘制对象中并被循环显示时,但是当我保存它时,它只是一个没有可绘制对象的方形图像。 这甚至可能吗?