Android Open Source - camera File Util






From Project

Back to project page camera.

License

The source code is released under:

Apache License

If you think the Android project camera listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.yanzi.util;
/* w  ww . j av  a 2s .  co  m*/
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.os.Environment;
import android.util.Log;

public class FileUtil {
  private static final  String TAG = "FileUtil";
  private static final File parentPath = Environment.getExternalStorageDirectory();
  private static   String storagePath = "";
  private static final String DST_FOLDER_NAME = "PlayCamera";

  /**???????????
   * @return
   */
  private static String initPath(){
    if(storagePath.equals("")){
      storagePath = parentPath.getAbsolutePath()+"/" + DST_FOLDER_NAME;
      File f = new File(storagePath);
      if(!f.exists()){
        f.mkdir();
      }
    }
    return storagePath;
  }

  /**????Bitmap??sdcard
   * @param b
   */
  public static void saveBitmap(Bitmap b){

    String path = initPath();
    long dataTake = System.currentTimeMillis();
    String jpegName = path + "/" + dataTake +".jpg";
    Log.i(TAG, "saveBitmap:jpegName = " + jpegName);
    try {
      FileOutputStream fout = new FileOutputStream(jpegName);
      BufferedOutputStream bos = new BufferedOutputStream(fout);
      b.compress(Bitmap.CompressFormat.JPEG, 100, bos);
      bos.flush();
      bos.close();
      Log.i(TAG, "saveBitmap???");
    } catch (IOException e) {
      // TODO Auto-generated catch block
      Log.i(TAG, "saveBitmap:???");
      e.printStackTrace();
    }

  }


}




Java Source Code List

cn.bgxt.mediarecorderdemo.MainActivity.java
cn.bgxt.mediarecorderdemo.RecordActivity.java
com.example.android.photobyintent.AlbumStorageDirFactory.java
com.example.android.photobyintent.BaseAlbumDirFactory.java
com.example.android.photobyintent.FroyoAlbumDirFactory.java
com.example.android.photobyintent.PhotoIntentActivity.java
com.marcodinacci.book.acb.VideoActivity.java
org.yanzi.activity.CameraActivity.java
org.yanzi.camera.CameraInterface.java
org.yanzi.camera.preview.CameraTextureView.java
org.yanzi.util.CamParaUtil.java
org.yanzi.util.DisplayUtil.java
org.yanzi.util.FileUtil.java
org.yanzi.util.ImageUtil.java