android呼叫照相機拍照獲取照片並…
1.呼叫系統的照相機程式
Intent intent = newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,TAKE_PHOTO_WITH_DATA);
2.在onActivityResult中處理返回的data
final Bitmap photo = data.getParcelableExtra("data");
如果不需要做剪下處理就可以直接使用圖片了,比如輸出到ImageView上
imageView.setImageBitmap(photo);
如果需要做剪下處理,就繼續向下執行
3.做剪下處理
Intent
intent = newIntent("com.android.camera.action.CROP");
intent.setType("image
private
Button btnTake = null;
private
ImageView lblImage = null;
private
static final int PHOTO_PICKED_WITH_DATA = 3021;
private
static final int CAMERA_WITH_DATA = 3023;
@Override
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnTake
= (Button)findViewById(R.id.btnTake);
lblImage
= (ImageView)findViewById(R.id.lblImage);
btnTake.setOnClickListener(new
View.OnClickListener() {
@Override
public
void onClick(View v) {
//
TODO Auto-generated method stub
Intent
intent = newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,
CAMERA_WITH_DATA);
}
});
}
@Override
protected
void onActivityResult(int requestCode, int resultCode,Intent data)
{
//
TODO Auto-generated method stub
if(resultCode!=RESULT_OK)
return;
switch(requestCode){
case
CAMERA_WITH_DATA:
final
Bitmap photo = data.getParcelableExtra("data");