/** * 跳轉(zhuǎn)至系統(tǒng)相冊(cè) * * @param activity * 活動(dòng)實(shí)例 * @param requestCode * 請(qǐng)求碼 */ public static void startSystemAlbumForResult(Activity activity, int requestCode) { Intent intent = new Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI); activity.startActivityForResult(intent, requestCode); }
/** * 調(diào)用系統(tǒng)相機(jī) * * @param activity * 活動(dòng)實(shí)例 * @param requestCode * 請(qǐng)求碼 */ public static void startSystemCameraForResult(Activity activity, int requestCode) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); activity.startActivityForResult(intent, requestCode); }
/** * 啟動(dòng)系統(tǒng)截圖頁面 * * @param activity * 當(dāng)前活動(dòng)實(shí)例 * @param requestCode * 請(qǐng)求碼 * @param data * 相片Uri地址 * @param width * 剪裁后圖片的寬 * @param height * 剪裁后圖片的高 */ public static void startPhotoZoomForResult(Activity activity, int requestCode, Uri data, int width, int height) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(data, "image/*"); // crop為true時(shí)表示顯示的view可以剪裁 intent.putExtra("crop", "true"); // aspectX aspectY 是寬高的比例 intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); // outputX,outputY 是剪裁圖片的寬高 intent.putExtra("outputX", width); intent.putExtra("outputY", height); intent.putExtra("return-data", true); activity.startActivityForResult(intent, requestCode); }
/** * 獲取系統(tǒng)相冊(cè)返回的圖片路徑 * * @param context * 上下文對(duì)象 * @param data * 攜帶數(shù)據(jù)的Intent對(duì)象 * @return 圖片本地路徑 */ public static String getAlbumImgPath(Context context, Intent data) { Uri selectedImage = data.getData(); if (selectedImage == null) { return null; } String[] filePathColumns = { MediaStore.Images.Media.DATA }; Cursor c = context.getContentResolver().query(selectedImage, filePathColumns, null, null, null); c.moveToFirst(); int columnIndex = c.getColumnIndex(filePathColumns[0]); String picturePath = c.getString(columnIndex); c.close(); return picturePath; }
/** * 獲取系統(tǒng)相機(jī)返回的圖片Bitmap對(duì)象 * * @param context * 上下文對(duì)象 * @param data * 攜帶數(shù)據(jù)的Intent對(duì)象 * @return 圖片Bitmap對(duì)象 */ public static Bitmap getCameraImgBitmap(Context context, Intent data) { Bundle bundle = data.getExtras(); if (bundle != null) { return (Bitmap) bundle.get("data"); } return null; }