How to save an image in sdcard after applying RGB color filter in android

落花浮王杯 提交于 2019-12-06 02:45:22

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:

  1. Load Bitmap image from View.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!