我写的代码编辑图像,现在我要保存编辑后的图像在SD卡
image=(ImageView)findViewById(R.id.image);
Intent intent = getIntent();
File sdCardDirectory = Environment.getExternalStorageDirectory();
photo = (Bitmap) intent.getParcelableExtra("photoo");
image.setImageBitmap(photo);
试试这个,
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();
}
}
好吧,首先,你需要给在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 );
这是很简单的。
File outpt = new File( sdCardDirectory, "photo.jpeg" );
FileOutputStream outptOs = new FileOutputStream( outpt );
photo.compress( Bitmap.CompressFormat.JPEG, 90, outptOs );