Here you can find the source of saveImage(String filename, Bitmap bm)
Parameter | Description |
---|---|
filename | The file |
bm | The bitmap |
public static String saveImage(String filename, Bitmap bm)
/* Copyright (c) 2010-2014 ARTags Project owners (see http://www.artags.org) * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version.//from ww w . j a v a 2 s . c om * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; import android.graphics.Matrix; import android.os.Environment; import android.util.Log; import java.io.File; import java.io.FileOutputStream; import org.artags.android.app.apilevels.ApiLevel4; import org.artags.android.app.apilevels.ApiLevels; public class Main{ private static final String ROOT_DIRECTORY = "/ARTags"; /** * Save the image as file * @param filename The file * @param bm The bitmap * @return The file path */ public static String saveImage(String filename, Bitmap bm) { return BitmapUtil.saveImage(filename, bm, false); } /** * Save the image as file * @param filename The file * @param bm The bitmap * @param landscape The orientation * @return The file path */ public static String saveImage(String filename, Bitmap bm, boolean landscape) { File root = Environment.getExternalStorageDirectory(); if (root.canWrite()) { if (landscape) { Matrix matrix = new Matrix(); matrix.postRotate(-90); bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); } try { File directory = new File(root.getPath() + ROOT_DIRECTORY); if (!directory.exists()) { directory.mkdir(); } String filepath = directory.getPath() + "/" + filename; File file = new File(filepath); FileOutputStream fos = new FileOutputStream(file); bm.compress(Bitmap.CompressFormat.PNG, 0, fos); fos.close(); return filepath; } catch (Exception e) { Log.e("ARTags:BitmapUtil:saveImage", "Exception while writing the tag", e); } } else { Log.e("ARTags:BitmapUtil:saveImage", "Can't write on the volume"); } return null; } }