Skip to content Skip to sidebar Skip to footer

How Should I Save An Image On Android?

I was wondering what the most efficient way of saving an image on Android is. What my app basically does is this: you see a default credit card, next you can choose to scan a barco

Solution 1:

public boolean saveBitmap(Bitmap image, String name){
    try {
        FileOutputStream fos = context.openFileOutput(name, Context.MODE_PRIVATE);
        image.compress(Bitmap.CompressFormat.JPEG, 70, fos);
        fos.close();
        return true;
    }
    catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

public Bitmap getBitmap(String name){
    try {
        FileInputStream fis = context.openFileInput(name);
        Bitmap image = BitmapFactory.decodeStream(fis);
        return image;
    }
    catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

Post a Comment for "How Should I Save An Image On Android?"