갤러리에 사용자의 SD 카드에있는 모든 사진을 표시하는 앱이 있습니다. 처음에는 메모리 부족 문제가 있었지만 BitmapFactory 옵션에서 inSampleSize를 늘리면 문제가 완화되었습니다. 그러나 이미지가 표시되지 않는 경우가 간헐적으로보고되는 경우도 있습니다. Droid Eris 사용자 중 많은 수가 문제를 겪고있는 것으로 보입니다. 여기에 모든 사진 및 첨부 ImageAdapter를로드하는 방법은 다음과 같습니다Android : SD 카드에서 이미지 표시
private void loadAllPhotos() {
setContentView(R.layout.add_pictures);
String[] projection = {MediaStore.Images.Thumbnails._ID};
cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection,
null,
null,
MediaStore.Images.Thumbnails.IMAGE_ID);
column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
int size = cursor.getCount();
if (size == 0) {
Toast.makeText(thisContext, "Can't find pics on SDcard.", Toast.LENGTH_SHORT).show();
}
g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
}
ImageAdapter : 당신이 아직하지 않은 경우
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
int cursorCount = mCursor.getCount();
return cursorCount;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
System.gc();
if (convertView == null) {
try {
String [] proj={MediaStore.Images.Media.DATA};
mCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,proj, null, null, null);
column_index = mCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
mCursor.moveToPosition(position);
filename = mCursor.getString(column_index);
if (filename.endsWith(".jpg") || filename.endsWith(".png")) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 15;
Bitmap bm = BitmapFactory.decodeFile(filename, options);
i.setImageBitmap(bm);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(150, 150));
i.setBackgroundResource(mGalleryItemBackground);
System.gc();
}
} catch (Exception e) {
}
}
return i;
}
}
의견을 보내 주셔서 감사합니다. 나는 예외가 발생할 때 사용자가 스택 추적 이메일을 보낼 수 있도록 이미 사용자 정의 오류보고를 사용합니다. 내가 제안하고 변경 사항을 확인합니다. – polyclef