如何在android中应用RGB彩色滤镜后在SD卡中保存图像

Ram*_*mya 3 android colors colorfilter

目前我正在设计一个基于照片编辑的应用程序.虽然这样做我遇到了一个问题,即

  1. 我已经通过这个链接学习了"如何为图像应用RGB滤色器"的教程,本教程非常有用且很好.
  2. 但问题是在将RGB滤色器应用于图像后需要将更改的图像保存在SD卡中.
  3. 我为此搜索了很多但没有发现确切的事情.
  4. 他们中的许多人都使用油漆()但我没有得到如何使用它.
  5. 所以我的问题就是"在将RBG Coloration应用到图像后我需要将该图像保存在SD卡中,但我没有找到该怎么做"?

Dav*_*arl 5

如何将Android ImageView保存到SD卡

您有一个ImageView通过各种灯光效果和彩色滤镜修改过的,现在您希望将结果保存为SD卡,如.jpg或.png格式图像.

方法如下:

  1. Bitmap从中加载图片View.
  2. Bitmap图像保存到SD卡.

示例:
不要忘记测试异常并为清单添加必要的权限!

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;
}
Run Code Online (Sandbox Code Playgroud)