将 uiimage 裁剪为屏幕尺寸

发布于 2024-12-17 04:43:52 字数 167 浏览 2 评论 0原文

我的应用程序有一个功能,允许用户移动和缩放图像,就像使用 UIImagePickerController 设置 allowedEditing = YES 一样。

我的方法是有一个滚动视图,允许用户以 1-4 级缩放 滚动视图上只有图像视图。

最后,我想将图像裁剪为屏幕尺寸。我该怎么做呢?

My application have an function that allow user to move and scale the image just like setting allowsEditing = YES with UIImagePickerController.

My approach is having a scrollview which allow user to zoom with level 1-4
There is only a image view on the scrollview.

At the end, I want to crop the image as the screen size. How can I do it?

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

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

发布评论

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

评论(1

暮年慕年 2024-12-24 04:43:53

诀窍是捕获包含缩放/旋转图像的视图层。在这种情况下,您需要捕获滚动视图层而不是图像本身。

我有一个 UIImage 捕获类别...查看 我的文章并下载源代码。

更新:按照下面的评论裁剪部分图像...

首先捕获整个视图,然后将图像裁剪为在指定的矩形中使用以下方法UIImage+Resize类别(也在文章中...)

- (UIImage *)croppedImage:(CGRect)bounds;

The trick is to capture the layer of the view containing the scaled / rotated image. In this case you need to capture the scrollview layer NOT the image itself.

I have a UIImage capture category for this...check out my article and download the source code.

UPDATE: to crop part of the image as per the comment below...

First capture the whole view then crop the image to the specified rect using the following method in the UIImage+Resize category (also in the article...)

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