我已經創建了使用內置圖像捕捉活動來拍照的活動,但仍然無法將圖片存儲在SD卡中並查看捕獲的圖像。意向已啓動,我可以拍照,但當我點擊在確定(保存),沒有任何事情發生。下面是我的活動:Android圖片活動
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.picturelayout);
imageForUpload = (ImageView) findViewById(R.id.trackMePicture);
btnBack = (Button) findViewById(R.id.btnBack);
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri(this));
startActivityForResult(intent, TAKE_PHOTO_CODE);
}
/**
* @return
*/
private Uri getImageUri(Context context) {
// TODO Auto-generated method stub
File file =newFile(Environment.getExternalStorageDirectory(),context.getPackageName());
if(!file.exists())
file.mkdir();
File newFile=new File(file,new Date().toString()+".jpg");
Uri imagePath=Uri.fromFile(newFile);
return imagePath;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==TAKE_PHOTO_CODE){
if(resultCode==-1){
Toast.makeText(getApplicationContext(), "Result code : "+resultCode, Toast.LENGTH_LONG).show();
//Uri imagePath=getImageUri();
Bitmap b;
try {
b = Media.getBitmap(getContentResolver(), getImageUri(this));
imageForUpload.setImageBitmap(b);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
Toast.makeText(getApplicationContext(), "Result code : "+resultCode, Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(getApplicationContext(), "Request code : "+requestCode, Toast.LENGTH_LONG).show();
}
}
請使用搜索功能。關於如何將相機中的圖像保存到SD卡上,大約有600萬個問題。只要看看右邊的「相關」列表--->謝謝 – Simon