Android Bitmap Save saveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality)

Here you can find the source of saveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality)

Description

save Bitmapto File

Declaration

public static boolean saveBitmaptoFile(Bitmap bmp, String path,
            CompressFormat format, int quality) 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStream;

import android.graphics.Bitmap;

import android.graphics.Bitmap.CompressFormat;

public class Main {
    public static boolean saveBitmaptoFile(Bitmap bmp, String path,
            CompressFormat format, int quality) {
        OutputStream stream = null;
        try {/* w w w  .j  ava 2  s  .  c o  m*/
            File file = new File(path);
            File filePath = file.getParentFile();
            if (!filePath.exists()) {
                filePath.mkdirs();
            }
            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    return false;
                }
            }
            stream = new FileOutputStream(path);
            boolean rlt = bmp.compress(format, quality, stream);
            stream.close();
            return rlt;
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        } catch (Exception e) {
            // TODO: handle exception
            return false;
        }
    }
}

Related

  1. getImagePath(Context context, Bitmap inImage)
  2. saveBitmap(Bitmap bitmap, File file)
  3. saveBitmap(String bitName, Bitmap bitmap)
  4. saveBitmap(final Bitmap bitmap, final String savePath)
  5. saveBitmapFromScrollView(ScrollView scrollView, String path)
  6. saveImage(String filename, Bitmap bm)
  7. saveImage(String filename, Bitmap bm, boolean landscape)
  8. saveMyBitmap(String bitName, Bitmap mBitmap)
  9. saveToLocal(Bitmap bmp, String fileName)