一、调用相机:
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
MainActivity.this.startActivityForResult(intent, 300);
}});
二、在onActivityResult中接收照片
protected void onActivityResult(int requestCode, int resultCode, Intent data) { ....
}else if(requestCode == 300){
if(resultCode == RESULT_OK){
Bitmap bmap = data.getParcelableExtra("data");
ImageView imageview = (ImageView)this.findViewById(R.id.imageview);
imageview.setImageBitmap(bmap);
// 图像保存到文件中
FileOutputStream foutput = null;
try {
foutput = new FileOutputStream(this.imageFile);
bmap.compress(Bitmap.CompressFormat.PNG, 100, foutput);
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally{
if(null != foutput){
try {
foutput.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
this.mUri = Uri.fromFile(this.imageFile);
}
}