我一直在試圖製作一個小畫廊,並且位圖總是返回null。代碼是這樣的:位圖總是在android中返回null
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
//Toast.makeText(getApplicationContext(),imgArray2.length+ " Image path from gallery : " + imgArray2[position], Toast.LENGTH_SHORT).show();
//Bitmap bitmap = BitmapFactory.decodeFile(imgArray2[position]);
//Uri uri = Uri.parse(imgArray2[position]);
//Bitmap bitmap = decodeFile(new File(uri.toString()).getAbsoluteFile());
//Bitmap bitmap = BitmapFactory.decodeFile(uri.toString());
//int imgID = getResources().getIdentifier(path, "drawable", "mypack.pack");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 15;
Bitmap bitmap = BitmapFactory.decodeFile(imgArray2[position], options);
//i.setImageResource(imgArray2[position]);
i.setImageBitmap(bitmap);
//Uri uri = Uri.parse(imgArray2[position]);
Toast.makeText(getApplicationContext(), "Image path from gallery : " + imgArray2[position], Toast.LENGTH_SHORT).show();
//i.setImageURI(Uri.parse(imgArray2[position]));
i.setLayoutParams(new Gallery.LayoutParams(170, 170));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
正如你可以看到的註釋掉的代碼,我一直在嘗試很多選項。 setImageURI
的作品,但我需要縮小圖像,因爲我有很多。圖像在SD卡中。我檢查了圖像的路徑,它是正確的。這裏做錯了什麼?
添加從logcat的輸出 – Frohnzie 2012-08-04 16:14:29