非常奇怪,我通過查看插入到自己的數據庫中的_ID值來找到解決方案/答案。首先我注意到,當我選擇一個現有圖像時(通過內置的Android圖庫),我沒有得到完整大小的圖片。
當我第一次拍了一張照片,我縮放的圖像。所以區別在哪裏。在照片的_ID存儲在我的數據庫中的位置進行可視化。在我的情況下,也可能是大多數情況下,這發生在onActivityResult過程中。
首先來看看什麼我最初有:
if(requestCode == REQUEST_CAMERA && resultCode == RESULT_OK){
String timestamp = Long.toString(System.currentTimeMillis());
// get the picture
mPicture = (Bitmap)result.getExtras().get("data");
//save image to gallery
String pictureUrl = MediaStore.Images.Media.insertImage(getContentResolver(), mPicture, getResources().getString(R.string.app_name_short), timestamp);
insertPictureAttachment(mRowId.intValue(), Integer.parseInt(Uri.parse(pictureUrl).getLastPathSegment()));
的「insertPictureAttachment」 - 方法執行實際插入到數據庫中。
回想起來,這有點奇怪......製作一張照片,所以我可以製作一個URI,然後得到最後一個路徑段(這是_ID),所以我可以將它插入到我的數據庫。
最終,事實證明,我可以只用一行替換上面代碼:
insertPictureAttachment(mRowId.intValue(), Integer.parseInt(result.getData().getLastPathSegment()));
要短得多,實際上更有意義......而不是正從result.getExtras的信息() .get(「data」),我從result.getData()得到我的信息,它給出了原始的全尺寸圖像的_ID。
我會對此做一些進一步的研究,因爲我不清楚爲什麼我實際上不必調用MediaStore.Images.Media.insertImage(...)...也許我將不得不如果我想要特定功能(如自定義文件位置或類似的東西)。
Greetingz, 柯恩<
嘗試使用yourImageView.setImageDrawable(yourNewPicture);如果這不是你已經在做什麼來顯示預覽 – Sephy 2010-08-09 19:30:19