Android Bitmap Save saveJPEGBitmap(Bitmap bmp, String path)

Here you can find the source of saveJPEGBitmap(Bitmap bmp, String path)

Description

save JPEG Bitmap

Declaration

public static boolean saveJPEGBitmap(Bitmap bmp, String path) 

Method Source Code

//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

public class Main {
    public static boolean saveJPEGBitmap(Bitmap bmp, String path) {
        return saveBitmap(bmp, path, Bitmap.CompressFormat.JPEG);
    }//from ww w  . j a v  a2 s . co  m

    private static boolean saveBitmap(Bitmap bmp, String path,
            CompressFormat format) {
        if (bmp == null || path == null) {
            return false;
        }
        try {
            File file = new File(path);
            if (!file.exists()) {
                file.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(file);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bmp.compress(format, 100, baos);
            fos.write(baos.toByteArray());
            baos.flush();
            fos.flush();
            baos.close();
            fos.close();

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}

Related

  1. saveBitmapAsJpgAtSd(Bitmap mBitmap, String dirPath, String fileName)
  2. saveBitmapFromView(View view, String path)
  3. saveBitmapJPEGWithBackgroundColor( String strFileName, Bitmap bitmap, int nQuality, int nBackgroundColor)
  4. saveBitmapPNGWithBackgroundColor( String strFileName, Bitmap bitmap, int nBackgroundColor)
  5. saveBitmapToPath(Context ctxt, String path, String filename, Bitmap bm)
  6. saveJpegFile(String fileName, Bitmap bitmap)
  7. savePNGBitmap(Bitmap bmp, String path)
  8. storeBitmapToFile(Bitmap bitmap, String filePath)
  9. writeToFile(Bitmap bitmap, String filePath, int quality)