适用于 iOS 的图像裁剪 API
Objective C 是否有任何裁剪图像 API 可以在 Xcode 项目中动态裁剪图像?请提供一些如何在 iPhone 中裁剪相机图像的技巧或技巧。
Is there any cropping image API for objective C that crops images dynamically in Xcode project? Please provide some tricks or techniques how could I crop camera images in iPhone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用下面的简单代码来裁剪图像。您必须传递图像和 CGRect(即裁剪区域)。在这里,我裁剪图像,以便获得原始图像的中心部分,并且返回的图像是正方形的。
You can use below simple code to crop an image. You have to pass the image and the CGRect which is the cropping area. Here, I crop image so that I get center part of original image and returned image is square.
编辑 - Swift 版本
所有这些解决方案看起来都相当复杂,其中许多实际上降低了图像质量。
您可以使用 UIImageView 的开箱即用方法来简化操作。
Objective-C
这将根据您为
UIImageView
设置的尺寸(我在此处称为我的imageView
)裁剪您的图像。就是这么简单,而且比其他解决方案效果更好。
EDIT - Swift Version
All these solutions seem quite complicated and many of them actually degrade the quality the image.
You can do much simpler using
UIImageView
's out of the box methods.Objective-C
This will crop your image based on the dimensions you've set for your
UIImageView
(I've called mineimageView
here).It's that simple and works much better than the other solutions.
您可以使用 CoreGraphics 框架动态裁剪图像。
这是动态图像裁剪的示例代码部分。我希望这对您有帮助。
You can use CoreGraphics framework to cropping image dynamically.
Here is a example code part of dynamic image crop. I hope this will be helpful for you.
Xcode 5、iOS 7 和 4 英寸屏幕示例:这是一个开源示例
SimpleImageCropEditor(项目压缩包和源代码示例)。您可以将图像裁剪编辑器作为模态视图控制器加载查看代码,请留下关于此示例代码是否回答问题“iOS 的图像裁剪 API”的建设性评论,
这是示例源 Objective-C 代码,使用。 UIImagePickerController、@protocol、UIActionSheet、UIScrollView、UINavigationController、MFMailComposeViewController 和 UIGestureRecognizer。
Xcode 5, iOS 7, and 4-inch screen example: Here is an open source example of a
SimpleImageCropEditor (Project Zip and Source Code Example. You can load the Image Crop Editor as a Modal View Controller and reuse. Look at the code and please leave constructive comments concerning if this example code answers the question "Image Cropping API for iOS".
Demonstrates, is example source Objective-C code, use of UIImagePickerController, @protocol, UIActionSheet, UIScrollView, UINavigationController, MFMailComposeViewController, and UIGestureRecognizer.