Android: convert Bitmap to File

-1

I have a problem converting a Bitmap which is an image, to File . I hope and you can help me.

To convert to File my image what I did was the following

ByteArrayOutputStream bos = new ByteArrayOutputStream();
nameImage.compress(Bitmap.CompressFormat.JPEG, 70, bos);
    
asked by Javier fr 16.12.2016 в 18:54
source

1 answer

1

Try this

private static void convertBitmapToFile(Bitmap bitmap, String name) {
    File filesDir = getAppContext().getFilesDir();
    File imageFile = new File(filesDir, name + ".jpg");

    OutputStream os;
    try {
        os = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
        os.flush();
        os.close();
    } catch (Exception e) {
        Log.e(getClass().getSimpleName(), "Error writing bitmap", e);
    }
}
    
answered by 16.12.2016 в 18:57