简体   繁体   English

从UIImagePicker裁剪UIImage的特定区域

[英]Crop a specific area of an UIImage from an UIImagePicker

my heading is exploding with this issue. 我的标题与此有关。

I am want to implement something similar to the camera view of Instagram. 我想实现类似于Instagram相机视图的功能。 I am using an Overlay View to customise the appearance of the camera. 我正在使用叠加视图来自定义相机的外观。

First issue - I couldn't make the Live View a square. 第一个问题-我无法将实时显示设为正方形。 Therefore, I created views to cover parts of the live view and make a square. 因此,我创建了视图以覆盖实时视图的一部分并制作一个正方形。

This solution led to my second issue. 这个解决方案导致了我的第二个问题。 How can I crop the image that appears in the square that I made on the overlay view. 如何裁剪显示在叠加视图上的正方形中的图像。

My closest solution has come from this post: UIImage: Resize, then Crop 我最接近的解决方案来自于这篇文章: UIImage:调整大小,然后裁剪

Is there a way to make a square shape live preview and the use that image. 有没有一种方法可以制作方形实时预览并使用该图像。 Or can I make a square from a portion of the scryeen that I want without distortion or lost of quality. 或者我可以在不希望变形或质量损失的情况下,用我想要的网纹幕布的一部分制作一个正方形。

Regards 问候

GPUImage is a great framework for processing live camera feeds. GPUImage是用于处理实时摄像机供稿的绝佳框架。 It can easily implement many visual effects, including cropping. 它可以轻松实现许多视觉效果,包括裁剪。

For example, to make a square video feed from the rectangular camera input: 例如,要从矩形摄像机的输入中输入方形视频,请执行以下操作:

GPUImageStillCamera *camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionBack];
camera.outputImageOrientation = UIInterfaceOrientationPortrait;

// 720 / 1280 = 0.5625
GPUImageCropFilter *squareCrop = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0, 0.21875, 1.0, 0.5625)];

[camera addTarget:squareCrop];
[squareCrop addTarget:self.imageView];
[camera startCameraCapture];

You will need to read the GPUImage documentation to learn how to set up the framework properly, but it is quite powerful once you learn how to use it. 您将需要阅读GPUImage文档,以学习如何正确设置框架,但是一旦学习了如何使用它,它就会非常强大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM