Android 从外部存储器获取位图

Android 从外部存储器获取位图,android,fileinputstream,fileoutputstream,android-bitmap,Android,Fileinputstream,Fileoutputstream,Android Bitmap,我已经通过FileOutputStream将一个位图保存到外部存储器中,并尝试在另一个类中检索该文件,以便将其放入imageView中。下面是保存位图的位置: public void SaveImage(Bitmap default_b) { String root = Environment.getExternalStorageDirectory().toString(); File myDir = new File(root + "/saved_images");

我已经通过FileOutputStream将一个位图保存到外部存储器中,并尝试在另一个类中检索该文件,以便将其放入imageView中。下面是保存位图的位置:

public void SaveImage(Bitmap default_b) {

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/saved_images");
    myDir.mkdirs();
    Random generator = new Random();
    int n = 100000;
    n = generator.nextInt(n);
    String fname = "Image-" + n +".png";
    File file = new File (myDir, fname);
    Log.i("AppInfoAdapter", "" + file);
    if (file.exists()) file.delete();
    try {
        // File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
            //  + "/" + fname + ".png");
        // FileOutputStream out = mContext.getApplicationContext().openFileOutput("bitmapA", Context.MODE_WORLD_WRITEABLE);
        FileOutputStream out = new FileOutputStream(file);
        default_b.compress(Bitmap.CompressFormat.PNG, 90, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
我试图在这里接受它:

  @Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Try to reuse the views
    ImageView view = (ImageView) convertView;
    // if convert view is null then create a new instance else reuse it
    if (view == null) {
        view = new ImageView(Context);
        Log.d("GridViewAdapter", "new imageView added");
    }
    try {
        FileInputStream in = Context.openFileInput("bitmapA");
        BufferedInputStream buf = new BufferedInputStream(in);
        byte[] bitMapA = new byte[buf.available()];
        buf.read(bitMapA);
        Bitmap bM = BitmapFactory.decodeByteArray(bitMapA, 0, bitMapA.length);
        view.setImageBitmap(bM);
        if (in != null) {
            in.close();
        }
        if (buf != null) {
            buf.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    view.setImageResource(drawables.get(position));
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setLayoutParams(new android.widget.GridView.LayoutParams(70, 70));
    view.setTag(String.valueOf(position));
    return view;
}
我在这方面做了大量的研究,并遇到了多种做同一件事的方法,但目前,这种方法不起作用

我看到了使用openFileOutput和openFileInput的地方,然后我还看到了人们创建新的FileInput和Output流的地方

哪一个更好地用于位图

然后根据哪一个更好使用(因为我都为保存位图进行了设置),如何从外部存储器获取位图

谢谢