2011-08-04 188 views
6

我想從手機的SD卡中選擇一張圖片。我使用下面的代碼來選擇和我的活動,以顯示將圖像轉換爲位圖android

Uri selectedImageUri = data.getData(); 
selectedImagePath = getPath(selectedImageUri); 
Uri uri = Uri.parse(selectedImagePath); 
uploadimage.setImageURI(uri); 

它工作正常,但我想這個圖像轉換爲Bitmap,我有圖像路徑和URI。

如何在這種情況下將圖像轉換爲位圖?請提前幫助,幫助我。

+0

使用這個鏈接.. http://www.higherpass.com/Android/Tutorials/Working-With-Images-In-Android/2/ – Uttam

+0

你可以閱讀關於使用位圖的地方http://maximbogatov.wordpress.com/2011/08/03/bitmaps-in-android/有一個例子,如何從路徑獲取Bitmp。 – Maxim

回答

20

使用此代碼

Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); 
+0

真棒,很高興你發佈了這個。 –

0
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uri); 
ImageView imageView = (ImageView) findViewById(R.id.imageView); 
imageView.setImageBitmap(bitmap);