Android:将图像裁剪为特定大小

时间:2012-02-22 02:09:39

标签: android image image-processing camera crop

我的目的是让用户从图库中选择一个图像,然后进行裁剪活动。但是,我需要将定义裁剪蒙版的矩形锁定到某个尺寸,然后用户只需重新定位它以显示图像的一部分。

关于如何做到这一点的任何想法?

谢谢

-T

2 个答案:

答案 0 :(得分:15)

Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null)
            .setType("image/*")
            .putExtra("crop", "true")
            .putExtra("aspectX", width)
            .putExtra("aspectY", height)
            .putExtra("outputX", width)
            .putExtra("outputY", height)
            .putExtra("scale", true)
            .putExtra("scaleUpIfNeeded", true)
            .putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f))
            .putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

答案 1 :(得分:6)

您需要创建自定义ImageView类来实现图像的缩放和平移,并且可以在此图像上叠加固定的矩形image(transparent)。并且可以创建该位图的子位图。并将其保存在文件中。

createBitmap(Bitmap source, int x, int y, int width, int height);

此方法用于创建子位图。

http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/

实现缩放和平移之后,我不确定createBitmap是否可以从图像的可见部分创建子位图(即图像的一部分在缩放时在屏幕上不可见),所以请尝试从drawingCache()获取imageView并为其创建子位图。