我无法将我的图像带到从 SD 卡加载的新 activity

I can't able to take my Images to new activity that are loaded from SD card

图片activity

public class ImageAdapter extends BaseAdapter {


private Context context;
Bitmap bm;

ArrayList<String>images = new ArrayList<String>();



//  Integer[] images;
void add(String path) {
    images.add(path);
}


public ImageAdapter(Context c) {
    context = c;
}

@Override
public int getCount() {
    return images.size();
}

@Override
public Object getItem(int position) {

    return images;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ImageView imageView = new ImageView(context);
    if (convertView == null) {
        //     imageView.setImageResource(images[position]);
        //   imageView.setImageBitmap(images);
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageView.setLayoutParams(new GridView.LayoutParams(240, 240));
        return imageView;
    } else {
        imageView = (ImageView) convertView;

    }
     bm = decodeSampledBitmapFromUri(images.get(position), 220, 220);
    imageView.setImageBitmap(bm);
return imageView;
}

private Bitmap decodeSampledBitmapFromUri(String path, int reqWidth, int reqHeight) {
    Bitmap bm = null;
    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    bm = BitmapFactory.decodeFile(path, options);

    return bm;
}
public int calculateInSampleSize(

        BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {
        if (width > height) {
            inSampleSize = Math.round((float)height / (float)reqHeight);
        } else {
            inSampleSize = Math.round((float)width / (float)reqWidth);
        }
    }

    return inSampleSize;
}
}

主要Activity

gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i= new Intent(getApplicationContext(), FullImageActivity.class);
            i.putExtra("id", position);
            startActivity(i);

        }
    });

全图Activity

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_image);

    Intent i=getIntent();

    int position= i.getExtras().getInt("id");
    ImageAdapter imageAdapter= new ImageAdapter(this);





    ImageView imageView=(ImageView)findViewById(R.id.imageView);

     imageView.setImageBitmap(imageAdapter.bm); \here I have to show my images that are read from Storage


}

我无法正确传递它,因为我的数组列表是字符串。我尝试了很多我知道但无法正常工作的方法。我也从互联网上尝试过,但没有用。 我无法通过 fullimage activity 显示我的图像。我从 SD 卡读取图像,所以它没有显示在全视图中。提前致谢

您的代码未正确执行,因为它没有正确设置。 首先,考虑使用 Picasso 或 Glide 或 UniversalImageLoader 将图像加载到占位符中,以避免在图像中滚动时产生笨拙的用户体验。

其次,把位置传给第二activity不是你的目标。您正在尝试传递图像。所以传递图像哈哈,

First on your getItem() 

你应该 return 基于位置 images.get(position)

的个人图像

而不是 return 图片。

其次在您的点击处理程序中

或者像

一样把它作为额外的传递
intent.addExtra(myAdapter.getItem(position))

或者如果您已经有了列表,只需执行

intent.addExtra(myList.get(position))

or simply cheat with ActivityTwo.imageToShow = myList.get(position)
startActivityTwo

其中任何一个都可以正常工作。