gpt4 book ai didi

android - 从 SD 卡中获取多个图像以显示在 Coverflow 中

转载 作者:行者123 更新时间:2023-11-30 04:00:15 25 4
gpt4 key购买 nike

如何让多个图像显示在此封面流中。我收到空指针异常和其他问题。如何在不知道 SD 卡上有多少图像的情况下从 SD 卡加载图像?图片数量不固定。通过使用此代码,我能够毫无问题地显示一张图片:

i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png"));

它加载了一张图片,一张从 SD 卡指定的图片,并将所有 coverflow 图像制作为同一张图片,pic03.png,大约一打相同的图片填充了 coverflow。太好了,但是我想加载 SD 卡上的所有图像。所以每张图片都填满了 coverflow 的每个部分,而不是一张相同的图片填满了所有部分。

完全迷失在这里并尝试这样做并从 Logcat 得到空指针异常并且想知道为什么?有谁知道如何让它工作?

下面是我正在使用的代码,可以给你一些想法:请注意,当从 SD 卡上的指定地址加载一张图像时它确实有效。至少那部分效果很好,但是多张图片?

// added this code inside the onCreate method to load the cursor with images only if the IS_PRIVATE column
// in the sqlite database is equal to the integer 1

String[] img = { MediaStore.Images.Media._ID };
imagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img,
MediaStore.Images.Media.IS_PRIVATE + "='" + 1 +"'",null, MediaStore.Images.Media._ID + "");
image_column_index = imagecursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
count = imagecursor.getCount();

//-------------------------------------------------------------------
// ImageAdapter class is a nested class inside of the CoverFlowExample class

public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private FileInputStream fis;

// originally earlier version of this app loaded images from the R.drawable folder like this

private Integer[] mImageIds = {

// R.drawable.pic01,
// R.drawable.pic02,
// R.drawable.pic03,
// R.drawable.pic04,
// R.drawable.pic05,
// R.drawable.pic06,
// R.drawable.pic07,
// R.drawable.pic08,
// R.drawable.pic09
};

//---------------------------------------------------------------------
// getView() method that is in the ImageAdapter class that extends the BaseAdapter class
// this class is a nested class inside the CoverFlowExample class that extends Activity.
// the CoverFlowExample class is used to implement the coverflow part of the app as an Activity

public View getView(int position, View convertView, ViewGroup parent) {
// to load from resources like SD card
ImageView i = new ImageView(mContext);

// use for single image --> i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png"));

image_column_index = imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA);
imagecursor.moveToPosition(position);

int id = imagecursor.getInt(image_column_index);
i.setImageURIUri.withAppendedPathMediaStore .Images.Media.EXTERNAL_CONTENT_URI, ""+ id));

// image from R.drawable use --> i.setImageResource(mImageIds[position]);
i.setLayoutParams(new CoverFlow.LayoutParams(130, 130));
i.setScaleType(ImageView.ScaleType.MATRIX);
return i;

// return mImages[position]; <-- not using this as im am not getting image from R.drawable
}

最佳答案

问题似乎是 String[] img = { MediaStore.Images.Media._ID }
这是 imagecursor 中包含的唯一列,而您尝试获取 DATA 列,imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA)

关于android - 从 SD 卡中获取多个图像以显示在 Coverflow 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12612887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com