Android Utililty Methods Bitmap Save

List of utility methods to do Bitmap Save

Description

The list of methods to do Bitmap Save are organized into topic(s).

Method

voidaddBitmapToMemoryCache(String key, Bitmap bitmap)
add Bitmap To Memory Cache
if (getBitmapFromMemCache(key) == null) {
    mMemoryCache.put(key, bitmap);
Stringbase64Bitmap(Bitmap bitmap)
base Bitmap
ByteArrayOutputStream out = null;
try {
    out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    out.flush();
    out.close();
    byte[] imgBytes = out.toByteArray();
    return Base64.encodeToString(imgBytes, Base64.DEFAULT);
...
voidbitmap2File(Bitmap bitmap, File file)
bitmap File
bitmap2File(bitmap, file, CompressFormat.JPEG, 100);
InputStreambitmap2Stream(Bitmap bitmap)
bitmap Stream
return bitmap2Stream(bitmap, CompressFormat.JPEG, 100);
StringgetImagePath(Context context, Bitmap inImage)
get Image Path
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(
        context.getContentResolver(), inImage, "Title", null);
return path;
FilesaveBitmap(Bitmap bitmap, File file)
save Bitmap
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
FileOutputStream fo = new FileOutputStream(file);
fo.write(bytes.toByteArray());
fo.close();
return file;
booleansaveBitmap(String bitName, Bitmap bitmap)
save Bitmap
try {
    File temp = File.createTempFile("temp", ".png", new File(
            StringUtil.getNameDelLastPath(bitName)));
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(temp);
    } catch (FileNotFoundException e) {
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
    fOut.flush();
    fOut.close();
    if (temp.exists()) {
        File f = new File(bitName);
        if (f.exists()) {
            f.delete();
        FileUtil.moveFile(temp.getAbsolutePath(), bitName);
    return true;
} catch (IOException e) {
    e.printStackTrace();
return false;
voidsaveBitmap(final Bitmap bitmap, final String savePath)
save Bitmap
FileOutputStream fileOutputStream = null;
try {
    fileOutputStream = new FileOutputStream(savePath);
    bitmap.compress(Bitmap.CompressFormat.JPEG, DEAFULT_QUALITY,
            fileOutputStream);
    fileOutputStream.flush();
} catch (Exception e) {
    e.printStackTrace();
...
BitmapsaveBitmapFromScrollView(ScrollView scrollView, String path)
save Bitmap From Scroll View
int h = 0;
Bitmap bitmap = null;
for (int i = 0; i < scrollView.getChildCount(); i++) {
    h += scrollView.getChildAt(i).getHeight();
bitmap = Bitmap.createBitmap(scrollView.getWidth(), h,
        Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
...
booleansaveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality)
save Bitmapto File
OutputStream stream = null;
try {
    File file = new File(path);
    File filePath = file.getParentFile();
    if (!filePath.exists()) {
        filePath.mkdirs();
    if (!file.exists()) {
...