在我的代码中,相机应该拍照并将其保存在ImageView中。它一直很好,直到将图片保存到ImageView。它没有显示!
有我的错误:
这是我的代码:
public class MainActivity extends AppCompatActivity {
static final int REQUESTED_IMAGE_CAPTURE=1;
ImageView output;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button shot=(Button)findViewById(R.id.button);
output=(ImageView)findViewById(R.id.imageView);
if(!hasCamera())
shot.setEnabled(false);
}
private boolean hasCamera(){
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
}
public void lanch_camera(View view){
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,REQUESTED_IMAGE_CAPTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode==REQUESTED_IMAGE_CAPTURE && resultCode ==RESULT_OK){
Bundle extras=data.getExtras();
Bitmap pic=(Bitmap) extras.get("data");
output.setImageBitmap(pic);
}
}
}
请帮帮我。感谢。