将 uiimage 裁剪为屏幕尺寸
我的应用程序有一个功能,允许用户移动和缩放图像,就像使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诀窍是捕获包含缩放/旋转图像的视图层。在这种情况下,您需要捕获滚动视图层而不是图像本身。
我有一个 UIImage 捕获类别...查看 我的文章并下载源代码。
更新:按照下面的评论裁剪部分图像...
首先捕获整个视图,然后将图像裁剪为在指定的矩形中使用以下方法
UIImage+Resize
类别(也在文章中...)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...)