【问题标题】:I want to crop an image and type was view in image. How can I crop an image from camera using this type of cropping?我想裁剪图像并输入在图像中查看。如何使用这种类型的裁剪从相机裁剪图像?
【发布时间】:2015-11-03 10:17:01
【问题描述】:

如何裁剪图像?我尝试了一些使用意图的概念,但仍然失败。我想要这种类型的裁剪。

这是一张图片:

【问题讨论】:

  • 你能说得具体点吗?
  • 我只想像链接上面显示的那样裁剪图像。有 8 个裁剪点,我想从这 8 个点调整裁剪点。我使用 CropImageview 库但无法裁剪图像。跨度>
  • github.com/cesards/CropImageView 这是我可以使用的库的链接。
  • 你能分享这个项目吗?或一些代码?也许出了点问题……
  • 简单地说,我想从相机拍一张照片,然后像你在图像中看到的那样裁剪图像我该怎么做,我使用那个库,但这对我没有帮助。

标签: android image crop


【解决方案1】:

1.在其布局中有一个带有CropImageView 的活动。
2.用IntentstartActivityForResult启动相机活动来拍照。
3.在Activity中,覆盖onActivityResult获取图片位图并执行`CropImageView.setImageBitmap(bitmap),瞧!现在您可以裁剪它...
看看这个例子: Capture Image from Camera and Display in Activity

【讨论】:

    【解决方案2】:

    试试下面的代码:

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = 1; 
    Bitmap bm = BitmapFactory.decodeFile(imagePath, opts);
    Intent intent = new Intent("com.android.camera.action.CROP");              
    intent .setDataAndType(outputFileUri, "image/*");
    intent.putExtra("outputX",bm.getWidth());
    intent.putExtra("outputY", bm.getHeight());
    intent.putExtra("aspectX", 0);
    intent.putExtra("aspectY", 0);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", false); 
    startActivityForResult(intent, 2);
    

    以下参数起着至关重要的作用:

     intent.putExtra("aspectX", 0);
        intent.putExtra("aspectY", 0);
    

    更多信息: Android - Crop image taken from camera with resizable ,independant height and width of cropped area

    【讨论】:

    • 我已经完成了这种类型的裁剪图像,我想要我在 que 中查看的那种类型的裁剪。看到了,谢谢你的建议
    【解决方案3】:

    为您的活动创建一个 xml 文件,您将在其中在 main_imageview 中显示原始图像,并将另一个 imageview 作为子项添加到crop_main_layout 中,将裁剪矩形图像作为 src(9 个补丁图像)

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/crop_main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <LinearLayout
            android:id="@+id/imageview_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center" >
            <ImageView
                android:id="@+id/main_imageview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/transparent"
                android:scaleType="centerInside"
                android:padding="@dimen/crop_view_padding"/>
        </LinearLayout>
    </RelativeLayout>
    

    裁剪矩形图像视图可以是从 Imageview 派生的自定义类,它将处理所有 onTouchEvents 并提供调整大小/移动功能,一旦用户选择选择并在裁剪屏幕上按完成,使用选定的裁剪矩形裁剪图像(自定义裁剪矩形图像视图边界)。

    Bitmap.createBitmap(currentBitmap, cropRect.left, cropRect.top, cropRect.width(), cropRect.height());
    

    【讨论】:

      猜你喜欢
      • 2017-05-22
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 2016-12-27
      • 2015-08-10
      • 1970-01-01
      • 2014-12-09
      • 1970-01-01
      相关资源
      最近更新 更多