package com.wangbb.naruto.utils; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.provider.MediaStore; /** * @author yuweichen */ public class PhotoUtil { public static final int PHOTO_RESULT_CODE = 0; public static final int SELECT_RESULT_CODE = 1; public static final int PHOTO_REQUEST_CUT = 2; /** * ���� * * @param activity * @param folderPath * @param photoName */ public static void takePhoto(Activity activity, String folderPath, String photoName) { /* * File outVideoFile = new java.io.File(fileDir); if * (!outVideoFile.exists()) { outVideoFile.mkdirs(); } */ Intent it = new Intent("android.media.action.IMAGE_CAPTURE"); it.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(FileUtils.createFile(folderPath, photoName))); it.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); activity.startActivityForResult(it, PHOTO_RESULT_CODE); } /** * ѡ�񱾵�ͼƬ */ public static void selectLocalPic(Activity activity) { Intent intent = new Intent(); /* ʹ��Intent.ACTION_GET_CONTENT���Action */ intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); /* ����Pictures����Type�趨Ϊimage */ intent.setType("image/*"); /* ȡ����Ƭ�󷵻ر����� */ activity.startActivityForResult(intent, SELECT_RESULT_CODE); } public static void openSystemCamera(Activity activity, String folderPath, String photoName) { Intent cameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // ָ������������պ���Ƭ�Ĵ���·�� cameraintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(FileUtils.createFile(folderPath, photoName))); activity.startActivityForResult(cameraintent, PHOTO_RESULT_CODE); } public static void startPhotoZoom(Activity activity, Uri uri) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); // cropΪtrue�������ڿ�����intent��������ʾ��view���Լ��� intent.putExtra("crop", "true"); // aspectX aspectY �ǿ�ߵı��� intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); // outputX,outputY �Ǽ���ͼƬ�Ŀ�� intent.putExtra("outputX", 250); intent.putExtra("outputY", 250); intent.putExtra("return-data", true); intent.putExtra("noFaceDetection", true); activity.startActivityForResult(intent, PHOTO_REQUEST_CUT); } }