Android Bitmap Save saveBitmap(String bitName, Bitmap bitmap)

Here you can find the source of saveBitmap(String bitName, Bitmap bitmap)

Description

save Bitmap

Declaration

public static boolean saveBitmap(String bitName, Bitmap bitmap) 

Method Source Code

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Picture;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.view.View;
import android.webkit.WebView;
import android.widget.ScrollView;

public class Main{
    public static boolean saveBitmap(String bitName, Bitmap bitmap) {
        try {// w  ww . jav a2 s .  com
            File temp = File.createTempFile("temp", ".png", new File(
                    StringUtil.getNameDelLastPath(bitName)));
            FileOutputStream fOut = null;
            try {
                fOut = new FileOutputStream(temp);
            } catch (FileNotFoundException e) {
            }
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
            fOut.flush();
            fOut.close();
            if (temp.exists()) {
                File f = new File(bitName);
                if (f.exists()) {
                    f.delete();
                }
                FileUtil.moveFile(temp.getAbsolutePath(), bitName);
            }

            return true;

        } catch (IOException e) {
            e.printStackTrace();
        }

        return false;
    }
}

Related

  1. base64Bitmap(Bitmap bitmap)
  2. bitmap2File(Bitmap bitmap, File file)
  3. bitmap2Stream(Bitmap bitmap)
  4. getImagePath(Context context, Bitmap inImage)
  5. saveBitmap(Bitmap bitmap, File file)
  6. saveBitmap(final Bitmap bitmap, final String savePath)
  7. saveBitmapFromScrollView(ScrollView scrollView, String path)
  8. saveBitmaptoFile(Bitmap bmp, String path, CompressFormat format, int quality)
  9. saveImage(String filename, Bitmap bm)