Android Bitmap Save bitmap2File(Bitmap bitmap, File file)

Here you can find the source of bitmap2File(Bitmap bitmap, File file)

Description

bitmap File

Declaration

public static final void bitmap2File(Bitmap bitmap, File file) 

Method Source Code

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import android.media.ThumbnailUtils;
import android.util.Base64;
import android.view.View;

public class Main{
    public static final void bitmap2File(Bitmap bitmap, File file) {
        bitmap2File(bitmap, file, CompressFormat.JPEG, 100);
    }//from www .  j a  v  a  2  s . c o  m
    public static final void bitmap2File(Bitmap bitmap, File file,
            CompressFormat format, int quality) {
        if (bitmap == null) {
            throw new NullPointerException("source bitmap is null...");
        }
        if (file == null) {
            throw new NullPointerException("targe file is null...");
        }
        if (file.exists()) {
            file.delete();
        }
        FileOutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            LogUtility.d(e);
        }
        if (outputStream == null) {
            return;
        }
        bitmap.compress(format, quality, outputStream);
        try {
            outputStream.flush();
        } catch (IOException e) {
            LogUtility.d(e);
        } finally {
            StreamUtility.closeStream(outputStream);
        }
    }
}

Related

  1. addBitmapToMemoryCache(String key, Bitmap bitmap)
  2. base64Bitmap(Bitmap bitmap)
  3. bitmap2Stream(Bitmap bitmap)
  4. getImagePath(Context context, Bitmap inImage)
  5. saveBitmap(Bitmap bitmap, File file)
  6. saveBitmap(String bitName, Bitmap bitmap)