本文实例为大家分享了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;
}
}
您可能感兴趣的文章:android 调用系统的照相机和图库实例详解Android调用相机并将照片存储到sd卡上实现方法Android启动相机拍照并返回图片Android 简单的照相机程序的实例代码Android实现读取相机(相册)图片并进行剪裁Android自定义照相机详解Android实现从本地图库/相机拍照后裁剪图片并设置头像Android开发从相机或相册获取图片裁剪Android 调用系统相机拍摄获取照片的两种方法实现实例Android自定义照相机Camera出现黑屏的解决方法