0

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

image=(ImageView)findViewById(R.id.image);
        Intent intent = getIntent();
        File sdCardDirectory = Environment.getExternalStorageDirectory();
        photo = (Bitmap) intent.getParcelableExtra("photoo");
        image.setImageBitmap(photo);
4

3 回答 3

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();
    }
}
于 2012-10-26T14:43:34.053 回答
1

好的,首先您需要在 AndroidManifest.xml 中提供写入权限,如下所示,

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

现在让我们看看实际编写编辑图像的代码,

// Getting the SDCard Path
File sdcard = Environment.getExternalStorageDirectory();
File editedFile = new File( sdcard, "myphoto.jpeg" );

// if file is already exists then first delete it
if ( editedFile.exists() ) 
{   
    editedFile.delete(); 
}

FileOutputStream fOut = new FileOutputStream( editedFile );
photo.compress( Bitmap.CompressFormat.JPEG, 90, fOut );
于 2012-10-26T14:59:00.727 回答
0

这很简单。

File outpt = new File( sdCardDirectory, "photo.jpeg" );
FileOutputStream outptOs = new FileOutputStream( outpt );
photo.compress( Bitmap.CompressFormat.JPEG, 90, outptOs );
于 2012-10-26T14:39:45.133 回答