我在按鈕上使用onClick捕捉圖像。拍照後更新圖片庫不顯示所有圖片Android相機
PictureCallback myPictureCallback_JPG = new PictureCallback() {
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
FileOutputStream outStream = null;
try {
// Write to SD Card
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
outStream.write(arg0);
outStream.close();
Toast.makeText(Photo.this, "Image Saved to SD Card", Toast.LENGTH_SHORT).show();
System.out.println();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
camera.startPreview();
}};
圖像被保存在SD卡中。 然後用戶點擊發送按鈕,打開一個佈局,點擊ImageView打開一個圖像庫並點擊一個特定的圖像,URI被選中。
imageAttachPhoto = (ImageView)findViewById(R.id.imageViewPhotoOne);
imageAttachPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
imageAttachPhoto.setImageURI(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
但我不能夠查看圖像搶購在畫廊的代碼,但可以通過FileBrowser看到的圖像,當我在電腦打開SD卡,我可以看到的圖像,然後在Android顯示畫廊圖像也在代碼中。 讓我知道問題是什麼以及如何解決問題,期待您的回覆。 謝謝。
加上一個絕對完美...得到它的工作...但是,每當我想在肖像模式下的圖像方向將旋轉90度。任何關於如何設置它的想法。謝謝。 – Mukunda 2011-12-29 12:36:59
嗯..沒有得到你完全正確的原因你打電話給默認intent..anyway..if如果不通過互聯網解決方案,然後再提出一個問題,所以人們會幫助你。 – MKJParekh 2011-12-29 12:45:55
這將在KitKat +中引發SecurityException。嘗試Vossi的方法,或者使用MediaScannerConnection這裏使用:http://stackoverflow.com/questions/18624235/android-refreshing-the-gallery-after-saving-new-images – absk 2014-06-20 06:14:36