在相机叠加层中创建我们自己的裁剪矩形 [英] Creating our own crop rect in camera overlay

查看:14
本文介绍了在相机叠加层中创建我们自己的裁剪矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想说明我的基本要求,即在 UIImagePickerController 中为相机更改裁剪矩形的框架.

I want to state my basic requirement which is to change the frame for crop rect in UIImagePickerController for a camera.

我刚刚意识到无法更改裁剪矩形的框架.这让我只有一个选择,即创建我自己的相机叠加层,我可以在其中设置裁剪矩形的框架.我搜索了很多,但一无所获.我问过 以前 但什么也没得到.我什至不知道这是否可能,如果是,那么如何创建它并移动裁剪框,根据默认的 UIImagePickerController 裁剪矩形对其进行缩放.

I just realized that it is not possible to change frame for crop rect. That leaves me with only one option i.e to create my own camera overlay wherein I can set frame for crop rect. I searched a lot but found nothing. I asked previously but didn't get anything. I don't even know is it possible and if yes then how to create it and move the crop box, scale it in accordance to default UIImagePickerController crop rect.

推荐答案

你必须实现你自己的 CropRect.首先设置

You have to Implement your own CropRect. First set the

[picker setAllowsEditing:NO];

然后在 didFinishPickingMediaWithInfo 委托推送自己的 CropRect 视图

Then in didFinishPickingMediaWithInfo delegate Push your own CropRect View

CustomImageEditor *custom = [[CustomImageEditor alloc] initWithNibName:@"CustomImageEditor" bundle:nil];
[picker pushViewController:custom animated:YES];
[custom release];

在推送视图时,像这样将图像传递给自定义视图

while Pushing view pass the image to the Custom View like this

 UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
 custom.pickedImage = image;

在该 customView 中裁剪图像.

In that customView you crop the image.

要裁剪图像,请尝试这样..

For croping the image try like this..

CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
UIImage *image = [UIImage imageWithCGImage:imageRef];

这篇关于在相机叠加层中创建我们自己的裁剪矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆