设置UIImagePickerController的尺寸“移动和缩放” cropbox [英] Set dimensions for UIImagePickerController "move and scale" cropbox

查看:771
本文介绍了设置UIImagePickerController的尺寸“移动和缩放” cropbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

移动和缩放屏幕如何确定裁切框的尺寸?

How does the "move and scale screen" determine dimensions for its cropbox?

基本上,我想为CropRect设置固定的宽度和高度,让用户根据需要移动和缩放他的图像以适应该框。

Basically I would like to set a fixed width and height for the "CropRect" and let the user move and scale his image to fit in to that box as desired.

有没有人知道如何做到这一点? (或者如果甚至可能与UIImagePickerController)

Does anyone know how to do this? (Or if it is even possible with the UIImagePickerController)

谢谢!

推荐答案

不可能与UIImagePickerController不幸。我建议的解决方案是禁用图像选择器的编辑,并自己处理。例如,我把图像放在一个可滚动的,可缩放的图像视图中。在图像视图的顶部是固定位置裁剪引导视图,其绘制用户看到的裁剪指示符。假设引导视图具有可见矩形(要保留的部分)和边缘宽度(要丢弃的部分)的属性,您可以获得这样的裁剪矩形。您可以使用 UIImage +调整大小类别做实际裁剪。

Not possible with UIImagePickerController unfortunately. The solution I recommend is to disable editing for the image picker and handle it yourself. For instance, I put the image in a scrollable, zoomable image view. On top of the image view is a fixed position "crop guide view" that draws the crop indicator the user sees. Assuming the guide view has properties for the visible rect (the part to keep) and edge widths (the part to discard) you can get the cropping rectangle like so. You can use the UIImage+Resize category to do the actual cropping.

CGRect cropGuide = self.cropGuideView.visibleRect;
UIEdgeInsets edges = self.cropGuideView.edgeWidths;
CGPoint cropGuideOffset = self.cropScrollView.contentOffset;

CGPoint origin = CGPointMake( cropGuideOffset.x + edges.left, cropGuideOffset.y + edges.top );
CGSize size = cropGuide.size;
CGRect crop = { origin, size };

crop.origin.x = crop.origin.x / self.cropScrollView.zoomScale;
crop.origin.y = crop.origin.y / self.cropScrollView.zoomScale;
crop.size.width = crop.size.width / self.cropScrollView.zoomScale;
crop.size.height = crop.size.height / self.cropScrollView.zoomScale;

photo = [photo croppedImage:crop];

这篇关于设置UIImagePickerController的尺寸“移动和缩放” cropbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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