android开发中调用系统的相机和图库及图片的后期处理

调用系统相机和图库,裁剪图片

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) {

            startPhotoZoom(data.getData());
        } else {

        }
        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);

    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=androidstyleTheme.Dialog
    item name=androidwindowNoTitletrueitem
    item name=androidwindowFrame@nullitem
    item name=androidwindowIsFloatingtrueitem
    item name=androidwindowIsTranslucentfalseitem
    item name=androidbackground@androidcolortransparentitem
    item name=androidwindowBackground@androidcolortransparentitem
    item name=androidbackgroundDimEnabledtrueitem
style
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值