为 UIImagePickerController“移动和缩放"设置尺寸裁剪框 [英] Set dimensions for UIImagePickerController "move and scale" cropbox

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

问题描述

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

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+Resize 类别来进行实际裁剪.

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“移动和缩放"设置尺寸裁剪框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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