我想制作应用程序,我想在拍摄图像后使用相机,我想将该图像存储在SDCard中并在屏幕上显示该图像。
任何人都可以帮助我......
由于
答案 0 :(得分:2)
您可以在以下方法中调用系统相机:
private void startCameraActivity() {
File file = new File("/sdcard/test/test.jpg");
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, REQUEST_CODE_CAMERA);
}
调用完成后,您将获得使用onActivityResult:
的图片@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("MakeMachine", "requestCode:"+requestCode + ",resultCode: " + resultCode);
switch(requestCode){
case ModifyUserActivity.REQUEST_CODE_CAMERA:
switch (resultCode) {
case Activity.RESULT_CANCELED:
picFileName = null;
Log.i("MakeMachine", "User cancelled");
break;
case Activity.RESULT_OK:
File file = new File("/sdcard/test/test.jpg");
if(file.exists()){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(picFileName, options);
imgTakePhoto.setImageBitmap(bitmap);
imgTakePhoto.setVisibility(View.VISIBLE);
}
break;
default:
break;
}
break;
default:
break;
}
}
答案 1 :(得分:1)
使用 ACTION_IMAGE_CAPTURE
意图启动相机活动:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult( intent, 0 );
这里有一个详细的例子:http://labs.makemachine.net/2010/03/simple-android-photo-capture/,我认为适合你的问题是捕获图像,将其存储在SD卡中,然后在imageview中显示图像。
享受!!!