write Bitmap to JPEG format - Android android.graphics

Android examples for android.graphics:JPEG

Description

write Bitmap to JPEG format

Demo Code

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.util.Log;

public class Main{

    public final static String TAG = "VLC/AudioUtil";
    static void writeBitmap(Bitmap bitmap, String path)
            throws IOException {
        OutputStream out = null;//from  ww  w.  java2 s .c  o  m
        try {
            File file = new File(path);
            if (file.exists() && file.length() > 0)
                return;
            out = new BufferedOutputStream(new FileOutputStream(file), 4096);
            if (bitmap != null)
                bitmap.compress(CompressFormat.JPEG, 90, out);
        } catch (Exception e) {
            Log.e(TAG, "writeBitmap failed : " + e.getMessage());
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }

}

Related Tutorials