Presently I am designing an application based on photo editing. While doing this i encountered with a problem i.e.
- I have gone through a tutorial "how to apply RGB color filter for an image" from this link and this tutorial is very helpful and nice.
- But the problem is after applying RGB color filter to the image i need to save the changed image in sd card.
- I have googled a lot for this but didn't found exact thing.
- Many of them sugested to use paint() But im not getting how to use that.
- So exactly my problem is "After Applying RBG Coloration to image I need to save that image in SD Card, But I do not found the how to do it" ?
How to Save an Android ImageView to SD Card
You have an ImageView
which you've modified via various lighting effects and color filters and now you wish to save the result to the SD card as as a .jpg or .png format image.
Here's how:
- Load
Bitmap
image fromView
. - Save
Bitmap
image to SD card.
Example:
Don't forget to test for Exceptions and add the necessary permissions to your manifest!
ImageView imageView = <View to save to SD card>;
Bitmap bitmap = loadBitmapFromView(imageView);
final String pathTxt = Environment.getExternalStorageDirectory();
File storagePath = new File(pathTxt);
File file = new File(storagePath, "filename.jpg");
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
out.flush();
out.close();
private Bitmap loadBitmapFromView(View v) {
final int w = v.getWidth();
final int h = v.getHeight();
final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
final Canvas c = new Canvas(b);
//v.layout(0, 0, w, h);
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
v.draw(c);
return b;
}
Theree are two methods for this...
1.after applying RGB values save those values in a variables and apply that values to the image selected.
2.after applying RGB values take the image from image view and save it
来源:https://stackoverflow.com/questions/16206494/how-to-save-an-image-in-sdcard-after-applying-rgb-color-filter-in-android