Android Bitmap Save storeImage(Context context, Bitmap image)

Here you can find the source of storeImage(Context context, Bitmap image)

Description

store Image

Declaration

public static void storeImage(Context context, Bitmap image) 

Method Source Code

//package com.java2s;
import android.content.Context;
import android.graphics.Bitmap;

import android.os.Environment;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static void storeImage(Context context, Bitmap image) {
        File pictureFile = getOutputMediaFile(context);
        if (pictureFile == null)
            return;

        try {// w  w w.j av  a2  s. c o  m
            FileOutputStream fos = new FileOutputStream(pictureFile);
            image.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static File getOutputMediaFile(Context context) {
        File mediaStorageDir = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

        // Create the storage directory if it does not exist
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                return null;
            }
        }
        // Create a media file name
        String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm")
                .format(new Date());
        File mediaFile;
        String mImageName = "TCG_" + timeStamp + ".jpg";
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + mImageName);
        return mediaFile;
    }
}

Related

  1. saveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality)
  2. saveImage(String filename, Bitmap bm)
  3. saveImage(String filename, Bitmap bm, boolean landscape)
  4. saveMyBitmap(String bitName, Bitmap mBitmap)
  5. saveToLocal(Bitmap bmp, String fileName)
  6. saveBitmap(Bitmap bitmap, String filename)
  7. saveBitmap2SD(Bitmap bitmap, Context context, String filePath, String fileName)
  8. addImageAsApplication(ContentResolver cr, String name, long dateTaken, String directory, String filename, Bitmap source, byte[] jpegData)
  9. saveBitmapToFile(Bitmap bitmap, String path)