【问题标题】:android image preview example for cropping用于裁剪的android图像预览示例
【发布时间】:2014-06-02 13:23:23
【问题描述】:

许多应用程序(例如 Facebook)都具有此功能,在用户从其设备的图库中选择一张图片后,用户会被带到一个预览页面,他们可以在其中选择图片的裁剪版本。在查看了 SO(例如 How to crop image on camera preview "Goggles style" - Android)后,我发现 this link 是一个示例,但 zip 似乎正在出售(CameraPreview.zip)。由于该帖子有点旧,我想知道是否有人知道那里的另一个示例,或者他们是否知道如何做到这一点,请分享您的知识。谢谢。

【问题讨论】:

    标签: android camera surfaceview crop preview


    【解决方案1】:

    尝试以下代码,根据您的要求更改参数:

    Intent cropIntent = new Intent("com.android.camera.action.CROP");
    //indicate image type and Uri
    cropIntent.setDataAndType(fileUri, "image/*");
    //set crop properties
    //cropIntent.putExtra("crop", "true");
    //indicate aspect of desired crop
    cropIntent.putExtra("aspectX", 1);
    cropIntent.putExtra("aspectY", 1);
    
    //indicate output X and Y
    cropIntent.putExtra("outputX", 350);
    cropIntent.putExtra("outputY", 350);
    //retrieve data on return
    //cropIntent.putExtra("return-data", true);
    // some code to retriev an valid Uri
    cropUri =  Uri.fromFile(getOutputMediaFile(MEDIA_TYPE_IMAGE));
     cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, cropUri);
    //start the activity - we handle returning in onActivityResult
    startActivityForResult(cropIntent, CROP_REQ_CODE);
    

    您可以使用 OnActivityResult() 获取输出

    Bundle extras = data.getExtras();
    //get the cropped bitmap
    clickedPhoto = extras.getParcelable("data");
    

    【讨论】:

    • 我要不要用你提供的替换正常的画廊意图代码?我的意思是Intent gallery = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); gallery.setType("image/*"); startActivityForResult(gallery, GALLERY_PHOTO_REQUEST_CODE);
    • 在 OnActivityResult() 中获得 GALLERY_PHOTO_REQUEST_CODE 的结果后不会。您需要将 Uri 传递给 CROP 意图。
    • 有没有一种简单的方法来包含旋转功能?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 2015-02-02
    相关资源
    最近更新 更多