将图像保存在SD卡中

use*_*835 0 android sd-card

我已经编写了编辑图像的代码,现在我想将该编辑的图像保存在SD卡中

image=(ImageView)findViewById(R.id.image);
        Intent intent = getIntent();
        File sdCardDirectory = Environment.getExternalStorageDirectory();
        photo = (Bitmap) intent.getParcelableExtra("photoo");
        image.setImageBitmap(photo);
Run Code Online (Sandbox Code Playgroud)

vin*_*thp 5

试试这个,

 void saveImage() {

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/saved_images");

    String fname = "Image.jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete (); 
    try {
           FileOutputStream out = new FileOutputStream(file);
           myBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();

    } catch (Exception e) {
           e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)