Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从SD卡获取多个图像以显示在Coverflow中_Android_Image_External_Sd Card_Image Gallery - Fatal编程技术网

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

Android 从SD卡获取多个图像以显示在Coverflow中,android,image,external,sd-card,image-gallery,Android,Image,External,Sd Card,Image Gallery,如何让多个图像显示在此coverflow中。我遇到空指针异常和其他问题。如何能够从SD卡加载图像,而不知道SD卡上有多少图像?图像的数量不是固定的。通过使用以下代码,我可以让一张图像毫无问题地显示出来: i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png")); 它加载了一张SD卡上指定的图像,并将所有coverflow图像制作成同一张图像pic03.png,大约十几张相同的图像填充了封面流。这是伟大的,但我想加载S

如何让多个图像显示在此coverflow中。我遇到空指针异常和其他问题。如何能够从SD卡加载图像,而不知道SD卡上有多少图像?图像的数量不是固定的。通过使用以下代码,我可以让一张图像毫无问题地显示出来:

i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png"));
它加载了一张SD卡上指定的图像,并将所有coverflow图像制作成同一张图像pic03.png,大约十几张相同的图像填充了封面流。这是伟大的,但我想加载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
}
//在onCreate方法中添加了此代码,以便仅当是私有列时才使用图像加载光标
//在sqlite数据库中,值等于整数1
字符串[]img={MediaStore.Images.Media.\u ID};
imagecursor=managedQuery(
MediaStore.Images.Media.EXTERNAL\u CONTENT\u URI,img,
MediaStore.Images.Media.IS_PRIVATE+“=”+1+“”,null,MediaStore.Images.Media._ID+”;
image\u column\u index=imagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.\u ID);
count=imagecursor.getCount();
//-------------------------------------------------------------------
//ImageAdapter类是CoverFlowExample类内部的嵌套类
公共类ImageAdapter扩展了BaseAdapter{
int mGalleryItemBackground;
私有上下文;
私有文件输入流fis;
//此应用的早期版本最初从R.drawable文件夹加载图像,如下所示
私有整数[]图像ID={
//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
};
//---------------------------------------------------------------------
//扩展BaseAdapter类的ImageAdapter类中的getView()方法
//此类是扩展活动的CoverFlowExample类中的嵌套类。
//CoverFlowExample类用于将应用程序的coverflow部分作为活动实现
公共视图getView(int位置、视图转换视图、视图组父视图){
//从SD卡等资源加载
ImageView i=新的ImageView(mContext);
//用于单图像-->i.setImageBitmap(BitmapFactory.decodeFile(“/mnt/sdcard/pic03.png”);
image\u column\u index=imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA);
imagecursor.moveToPosition(位置);
int id=imagecursor.getInt(图像列索引);
i、 setImageURIUri.withAppendedPathMediaStore.Images.Media.EXTERNAL_CONTENT_URI,“+id”);
//来自R.drawable的图像使用-->i.setImageResource(mimageId[position]);
i、 setLayoutParams(新CoverFlow.LayoutParams(130130));
i、 setScaleType(ImageView.ScaleType.MATRIX);
返回i;

//返回mImages[position];问题似乎是
String[]img={MediaStore.Images.Media.\u ID}

这是
imagecursor
中唯一包含的列,当您尝试获取
数据列时,
imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA)
问题似乎是
String[]img={MediaStore.Images.Media.\u ID}

这是
imagecursor
中唯一包含的列,当您尝试获取
数据列时,
imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA)

停止叫喊!这会使您的问题更难阅读。他们发明shift键是有原因的。键入所有大写字母会使文本更难阅读,这是一个错误d不会提高你得到答案的速度。我的帖子中只有5个大写的词,但由于你对所有大写的词都很敏感,我相信其他人也很敏感。目的是通过强调某些要点,而不是大喊大叫,使文本更清晰易读。但有些人不同意,这是公平的,如果这就是这里的文化,我已经把这5个字改成小写。但是我留下了“SD”这个字卡到大写的SD卡通常是这样写的。无论如何,谢谢你的评论。总是想改善我的沟通,融入这里的社区。你最初问题的90%的主题都是大写的,这就是我发表评论时所指的。你可以查看编辑历史来确认。尽可能phasis,此网站支持粗体和斜体,以及
代码格式设置
,无需为此键入大写。
SD
大写是合适的,就像
SDK
IBM
MS-DOS
一样。你是对的。很抱歉。我以为你是在帖子中提到书面材料,不是这篇文章的标题。标题全是大写的。我会更改它。我确信人们不喜欢看到这一点。我很高兴你花时间指出这一点。如果没有人告诉我我做错了什么,我永远也学不到。如果我做了任何疯狂的事情,让我知道。别大喊大叫!这会让你的问题更难理解。他们说输入shift键是有原因的。输入所有大写字母会使文本更难阅读,也不会提高您获得答案的速度。我的帖子中只有5个大写字母,但由于您对包含所有大写字母很敏感,我相信其他人也会这样做。目的是让文本更清晰易读通过强调某些要点,而不是大喊大叫。但有些人不同意,如果是这样的话,这是很公平的