0

我有一些按钮和一个图像视图。我从图库中加载照片,照片显示在图像视图中。对于每个按钮,都有一个单击方法可以应用,该方法为图像应用一种效果。还有另一个按钮,用于将照片保存在内部存储中。我想在应用其中一种效果后保存照片。我搜索了,但我只是发现如何保存没有效果的照片。有人知道如何使用 on click 方法在应用效果后保存图像。

4

1 回答 1

0

ImageView您可以通过调用此函数来简单地获取位图:

Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap()

然后使用输入/输出流将位图保存在所需的位置:

private void saveBitmapFromImageView(File destFile, ImageView imageView){

    Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap()
    OutputStream os;
    try {
        os = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
    } catch(Exception e) {
        Log.e(TAG, "saveBitmapFromImageView", e);
    } finally {
        IOUtils.closeQuietly(os);
    }
}

编辑#1:

IOUtils是 Apache commons lib,添加到你的 gradle:

compile 'org.apache.commons:commons-io:1.3.2'
于 2016-09-16T01:19:35.450 回答