private static final int PHOTO_REQUEST_TAKEPHOTO = 1;// 拍照    private static final int PHOTO_REQUEST_GALLERY = 2;// 从相册中选择    private static final int PHOTO_REQUEST_CUT = 3;// 结果    private File tempFile = new File(Environment.getExternalStorageDirectory(),            getPhotoFileName());    protected void onActivityResult(int requestCode, int resultCode, Intent data) {        switch (requestCode) {        case PHOTO_REQUEST_TAKEPHOTO:// 当选择拍照时调用            startPhotoZoom(Uri.fromFile(tempFile));            break;        case PHOTO_REQUEST_GALLERY:// 当选择从本地获取图片时            // 做非空判断,当我们觉得不满意想重新剪裁的时候便不会报异常,下同            if (data != null) {                System.out.println("11================");                startPhotoZoom(data.getData());            } else {                System.out.println("================");            }            break;        case PHOTO_REQUEST_CUT:// 返回的结果            if (data != null)                // setPicToView(data);                sentPicToNext(data);            break;        }        super.onActivityResult(requestCode, resultCode, data);    }
 // 使用系统当前日期加以调整作为照片的名称    private String getPhotoFileName() {        Date date = new Date(System.currentTimeMillis());        SimpleDateFormat dateFormat = new SimpleDateFormat(                "'IMG'_yyyyMMdd_HHmmss");        return dateFormat.format(date) + ".jpg";    }

调用系统拍照功能:

Intent cameraintent = new Intent(                                    MediaStore.ACTION_IMAGE_CAPTURE);                            // 指定调用相机拍照后照片的储存路径                            cameraintent.putExtra(MediaStore.EXTRA_OUTPUT,                                    Uri.fromFile(tempFile));                            startActivityForResult(cameraintent,                                    PHOTO_REQUEST_TAKEPHOTO);

调用系统相册功能:

Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);                            getAlbum.setType("image/*");                            startActivityForResult(getAlbum, PHOTO_REQUEST_GALLERY);

调用系统裁剪功能:

private void startPhotoZoom(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", 300);        intent.putExtra("outputY", 300);        intent.putExtra("return-data", true);        intent.putExtra("noFaceDetection", true);        System.out.println("22================");        startActivityForResult(intent, PHOTO_REQUEST_CUT);    }

自定义对话框:

        mDialog = new AlertDialog.Builder(this, R.style.FullScreenDialog)                .create();        if (mDialog != null && !mDialog.isShowing()) {            mDialog.show();            mDialog.setContentView(R.layout.dialog_select_imge);            mDialog.setCanceledOnTouchOutside(false);
}

自定义style :

<style name="FullScreenDialog" parent="android:style/Theme.Dialog">        <item name="android:windowNoTitle">true</item>        <item name="android:windowFrame">@null</item>        <item name="android:windowIsFloating">true</item>        <item name="android:windowIsTranslucent">false</item>        <item name="android:background">@android:color/transparent</item>        <item name="android:windowBackground">@android:color/transparent</item>        <item name="android:backgroundDimEnabled">true</item>    </style>

更多相关文章

  1. 理解 Android(安卓)Build 系统
  2. Android编译系统参考手册
  3. android调用平台功能
  4. android锁屏页面实践
  5. android emulator连接internet
  6. Android(安卓)Service 弹出系统全局Dialog
  7. Android:onNewIntent()触发机制及注意事项
  8. android调用系统联系人列表
  9. js 判断手机操作系统(ios或Android)

随机推荐

  1. Android(安卓)SDcard目录文件操作
  2. 【Android】使用ConnectivityManager与Ne
  3. Android动态设置控件高度
  4. Android(安卓)Studio 打包方式
  5. [转]Android文字跑马灯控件
  6. 各种奇妙的hack
  7. Android(安卓)Intent传递对象和集合
  8. android intent深入解析
  9. 网上找了些Android数据库操作的代码
  10. Android(安卓)ListView滑动时出现黑屏解