我已經和ImageView的,它應該是充滿圖像從畫廊與此代碼:setImageBitmap()不工作
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getIntent, "Pick an image.");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE_REQUEST);
現在,一切都很好在這部分代碼,問題是在onActivityResult()中,完全在setImageBitmap()中,因爲imageView沒有采用來自Gallery的圖像。這是onActivityResult()代碼:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PICK_IMAGE_REQUEST || resultCode == PromoUpload.RESULT_OK){
Uri selectedImage = data.getData();
String[] filepathColumm = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filepathColumm, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filepathColumm[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
imagePromo.setImageBitmap(bitmap);
pictureFlag = 1;
}
我敬酒picturePath
屬性和它的顯示OK,問題正是在這裏:
Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
imagePromo.setImageBitmap(bitmap);
但我不知道我在做什麼錯誤。這是ImageView的的XML:
<ImageView
android:id="@+id/imageView_promo"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:padding="1dp" />
我也嘗試選擇從多個尺寸的圖像,但它似乎沒有工作...
謝謝!替換幫助。無論如何,正如你所說,我會嘗試將Glide或畢加索實施到我的項目中。 –