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

北城余情 提交于 2019-12-07 13:35:41

问题


Presently I am designing an application based on photo editing. While doing this i encountered with a problem i.e.

  1. 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.
  2. But the problem is after applying RGB color filter to the image i need to save the changed image in sd card.
  3. I have googled a lot for this but didn't found exact thing.
  4. Many of them sugested to use paint() But im not getting how to use that.
  5. 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" ?

回答1:


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;
}



回答2:


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

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