Android相机管理工具类

本文实例为大家分享了Android相机管理工具类的具体代码,供大家参考,具体内容如下

package com.utils.tools; 
 
import java.io.BufferedOutputStream; 
import java.io.File; 
import java.io.FileOutputStream; 
 
import com.shennongshi.dingdong.R; 
import com.shennongshi.dingdong.pztools.IntentConstant.RequestCode; 
import com.third.imageloader.ImageCache; 
 
import android.app.Activity; 
import android.content.Intent; 
import android.graphics.Bitmap; 
import android.os.Environment; 
import android.text.TextUtils; 
 
public class CameraUtils { 
   
  private static final String PICTURES = "picture"; 
  private static String IMG_PATH_NAME = ""; 
   
  public static void getImageFromAlbum(Activity act) { 
    Intent intent = new Intent(Intent.ACTION_PICK); 
    intent.setType("image/*"); 
    act.startActivityForResult(intent, RequestCode.REQUEST_CODE_PICK_IMAGE); 
  } 
 
  public static void getImageFromCamera(Activity act) { 
    String state = Environment.getExternalStorageState(); 
    if (state.equals(Environment.MEDIA_MOUNTED)) { 
      Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE"); 
      act.startActivityForResult(getImageByCamera, RequestCode.REQUEST_CODE_CAPTURE_CAMEIA); 
    } else { 
      XToaster.show(R.string.qqryjcrSDk); 
    } 
  } 
   
  public static void createFile(Activity act) { 
    if (TextUtils.isEmpty(IMG_PATH_NAME)) { 
      String path = ImageCache.getDiskCacheDir(act, PICTURES).getAbsolutePath(); 
      File file = new File(path); 
      if (!file.exists()) file.mkdirs(); 
      IMG_PATH_NAME = path + "/" + System.currentTimeMillis() + ".jpg";  
    } 
  } 
 
  public static boolean saveImage(Bitmap photo) { 
    try { 
      BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(IMG_PATH_NAME, false)); 
      photo.compress(Bitmap.CompressFormat.JPEG, 100, bos); 
      bos.flush(); 
      bos.close(); 
    } catch (Exception e) { 
      return false; 
    } 
    return true; 
  } 
} 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。