Android:将图像裁剪为特定尺寸

发布于 2025-01-08 01:21:03 字数 128 浏览 1 评论 0原文

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

关于如何做到这一点有什么想法吗?

谢谢

-T

My intention is to have the user pick an image from the gallery, then have a cropping activity come up. However, I need the rectangle that defines the cropping mask to be locked to a certain dimension and then the user simply repositions it to display a portion of an image.

Any ideas on how this would be done?

Thanks

-T

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人的歌 2025-01-15 01:21:03
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());
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());
听,心雨的声音 2025-01-15 01:21:03

您需要创建一个自定义的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是否可以从可见创建子位图图像的一部分(即缩放时图像的一部分在屏幕上不可见),因此尝试从 imageView 获取 drawingCache() 并为其创建子位图相同。

You need to create a custom ImageView class to achieve zooming and panning of an image and can have a fixed rectangle image(transparent) overlaying on this image. And can create sub-bitmap of that bitmap. and save it in a file.

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

This method is used to create a sub-bitmap.

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

After achieving zooming and panning, I am not sure if createBitmap can create sub-bitmap from the visible portion of the image(i.e. part of image wont be visible on the screen when it is zoomed), So try getting the drawingCache() from imageView and create sub-bitmap for the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文