Android Bitmap Save saveBitmapToPath(Context ctxt, String path, String filename, Bitmap bm)

Here you can find the source of saveBitmapToPath(Context ctxt, String path, String filename, Bitmap bm)

Description

save Bitmap To Path

License

Apache License

Declaration

public static void saveBitmapToPath(Context ctxt, String path,
            String filename, Bitmap bm) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Rumblefish Mobile Toolkit for Android
 * //from w  ww.j  av  a  2  s  .c  om
 * Copyright 2013 Rumblefish, Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Use of the Rumblefish Sandbox in connection with this file is governed by
 * the Sandbox Terms of Use found at https://sandbox.rumblefish.com/agreement
 *  
 * Use of the Rumblefish API for any commercial purpose in connection with
 * this file requires a written agreement with Rumblefish, Inc.
 ******************************************************************************/

import java.io.File;

import java.io.FileOutputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

import android.os.Environment;

public class Main {
    public static void saveBitmapToPath(Context ctxt, String path,
            String filename, Bitmap bm) {
        File directory = new File(
                Environment.getExternalStorageDirectory(), path);
        if (!directory.exists())
            directory.mkdir();
        File lastFile = new File(directory, filename);

        try {
            if (lastFile.createNewFile() == false) {
                lastFile.delete();
                lastFile.createNewFile();
            }

            FileOutputStream ostream = new FileOutputStream(lastFile);
            bm.compress(CompressFormat.JPEG, 100, ostream);
            ostream.close();
        } catch (Exception e) {

        }
    }
}

Related

  1. saveBitmap(File saveToFile, Bitmap bitmapToSave)
  2. saveBitmapAsJpgAtSd(Bitmap mBitmap, String dirPath, String fileName)
  3. saveBitmapFromView(View view, String path)
  4. saveBitmapJPEGWithBackgroundColor( String strFileName, Bitmap bitmap, int nQuality, int nBackgroundColor)
  5. saveBitmapPNGWithBackgroundColor( String strFileName, Bitmap bitmap, int nBackgroundColor)
  6. saveJPEGBitmap(Bitmap bmp, String path)
  7. saveJpegFile(String fileName, Bitmap bitmap)
  8. savePNGBitmap(Bitmap bmp, String path)
  9. storeBitmapToFile(Bitmap bitmap, String filePath)