To Save The Image In Sdcard
I have Written the code for Editing the Image now I want to save that edited image in the sdcard image=(ImageView)findViewById(R.id.image); Intent intent = getIntent();
Solution 1:
Try this,
voidsaveImage() {
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();
}
}
Solution 2:
Ok first of all you need to give Write Permissions in AndroidManifest.xml as below,
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Now lets look at the code that actually write your edited image,
// Getting the SDCard PathFilesdcard= Environment.getExternalStorageDirectory();
FileeditedFile=newFile( sdcard, "myphoto.jpeg" );
// if file is already exists then first delete itif ( editedFile.exists() )
{
editedFile.delete();
}
FileOutputStreamfOut=newFileOutputStream( editedFile );
photo.compress( Bitmap.CompressFormat.JPEG, 90, fOut );
Solution 3:
It is quite simple.
Fileoutpt=newFile( sdCardDirectory, "photo.jpeg" );
FileOutputStreamoutptOs=newFileOutputStream( outpt );
photo.compress( Bitmap.CompressFormat.JPEG, 90, outptOs );
Post a Comment for "To Save The Image In Sdcard"