我想从内部存储器加载特定文件夹中的图像,如何加载图像?以及视频也是如此

时间:2017-10-14 10:38:18

标签: android image video gridview

public class ImageAdapter extends BaseAdapter  {
private File currentDir;
String SCAN_PATH;
File allFiles ;
private Context context;


public Integer[] images={

      //I want to load images here


};

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

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

@Override
public Object getItem(int position) {
    return images[position];
}

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

我想加载图片。我只需使用ID添加图像,但我想从内部/ SD卡存储加载图像。 我想知道如何添加图片

1 个答案:

答案 0 :(得分:0)

Try loading images into imageview as bitmap  
try {
        File f=new File(filepath, "imagename.jpg"); // internal or external storage path 
        Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
            ImageView img=(ImageView)findViewById(R.id.imgPicker);
        img.setImageBitmap(b);
    } 
    catch (FileNotFoundException e) 
    {
        e.printStackTrace();
    }

Hope this may work!