我想從圖庫中獲取圖像。它給了我像位圖一樣的圖像。我希望.jpg文件中的圖像能夠保存我的數據庫中的文件名。如何以.jpg文件格式從圖庫中獲取圖像?
我按照這個教程:
http://www.theappguruz.com/blog/android-take-photo-camera-gallery-code-sample
畫廊圖像中選擇代碼:
@SuppressWarnings("deprecation")
private void onSelectFromGalleryResult(Intent data) {
Bitmap bm=null;
if (data != null) {
try {
bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
}
Uri selectedImage = data.getData();
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor c = getContentResolver().query(selectedImage, filePath, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
String picturePath = c.getString(columnIndex);
c.close();
File file = new File(picturePath);// error line
mProfileImage = file;
profile_image.setImageBitmap(bm);
}
我嘗試這樣做。但我得到文件上的空指針。
例外:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
此外,我不希望這個新創建的文件被保存在外部存儲。這應該是一個臨時文件。我怎樣才能做到這一點?
謝謝..
請檢查http://stackoverflow.com/questions/5383797/open-an-image-using-uri-in-androids-default-gallery-image-viwer – Shailesh