【问题标题】:Define Size of the crop定义作物的大小
【发布时间】:2013-03-25 11:32:27
【问题描述】:

我想裁剪一张图片。但我遇到了一个问题:

如何定义裁剪的默认尺寸。我想在出现裁剪的矩形时定义它的大小和位置。

问候

Wazol

【问题讨论】:

  • 你尝试过什么吗?如果你这样做了,请告诉我们你正在使用的代码
  • 我已经尝试过使用 selva 的代码。我只发现了这一点,但这不是我想要的

标签: android crop


【解决方案1】:

使用下面的代码

您也可以使用此链接作为参考

点击Crop image using rectengle

   int targetWidth = 100;
      int targetHeight = 100;
      Bitmap targetBitmap = Bitmap.createBitmap(
   targetWidth, targetHeight,Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(targetBitmap);
 Path path = new Path();
    path.addRect(rectf, Path.Direction.CW);
     canvas.clipPath(path);
     canvas.drawBitmap( sourceBitmap,
       new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
     new Rect(0, 0, targetWidth, targetHeight), null);
    ImageView imageView = (ImageView)findViewById(R.id.my_image_view);
   imageView.setImageBitmap(targetBitmap);

【讨论】:

  • 查看下面的链接以获得解释。
【解决方案2】:

使用 Intent add Aspect Ratio 添加 outputX 和 outputY 参数

 Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");
    intent.setData(mImageCaptureUri);

    intent.putExtra("outputX", 200);
    intent.putExtra("outputY", 250);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);
    startActivityForResult(i, CROP_FROM_CAMERA);

【讨论】:

  • 不要使用这个意图。 CROP 操作并不存在于所有 Android 设备中,并且某些存在的设备的行为不同。实现这一点的最佳方法是创建一个自定义相机,具有定义的宽度和高度,以便用户在拍照时对其进行裁剪。
  • 没有其他方法可以在自定义相机上裁剪定义宽度和高度的图像吗?我只想在基本裁剪上定义默认大小和位置
  • 试试这个链接可以帮助你androidhub4you.com/2012/07/…
猜你喜欢
  • 1970-01-01
  • 2016-04-14
  • 1970-01-01
  • 1970-01-01
  • 2018-01-14
  • 1970-01-01
  • 2019-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多