简体   繁体   English

需要在UIImagePickerController上覆盖一个很小的形状(矩形),然后相应地裁剪图像-更新

[英]need a very tiny (rectangular in shape) overlay over UIImagePickerController, and then crop the image accordingly - UPDATED

In my application, i need the user to take a snap of only a 10 letter word (using overlay , which should be right in the centre of the screen of the UIImagePicker ), and then in need to show him that image (only the part of the image covered by that rectangle). 在我的应用程序中,我需要用户仅捕捉一个10个字母的单词(使用overlay ,应该在UIImagePicker屏幕的中心),然后需要向他展示该图像(仅一部分)该矩形所覆盖的图像的大小)。 So, I need to crop that image according to the overlay. 因此,我需要根据覆盖图裁剪该图像。

Here, i have taken a picture using UIImagePickerControl. 在这里,我使用UIImagePickerControl拍照。 Now, i want to see the dimensions of the image that i have taken.. 现在,我想查看所拍摄图像的尺寸。

UIImage *imageToprocess = [info objectForKey:UIImagePickerControllerOriginalImage];

NSLog(@"image width %f", imageToprocess.size.width);
NSLog(@"image height %f", imageToprocess.size.height);

I see the following result on console.. But how is this possible. 我在控制台上看到以下结果。但这怎么可能。 the dimensions of the image is exceeding the dimension of the iPhone screen size.. (which is 320, 568) 图片的尺寸超过了iPhone屏幕尺寸的尺寸。(分别为320、568)

UsingTesseractOCR[524:60b] image width 2448.000000
2013-12-17 16:02:18.962 UsingTesseractOCR[524:60b] image height 3264.000000

Can anybody help me out here?? 有人可以帮我吗? I have gone through several questions here, but did not understand how to do it. 我在这里经历了几个问题,但不明白该怎么做。

Please help.. 请帮忙..

Refer this sample code for image capturing and cropping. 请参考此示例代码进行图像捕获和裁剪。

https://github.com/kishikawakatsumi/CropImageSample https://github.com/kishikawakatsumi/CropImageSample

For creating overlay, first create a custom view (of full dimensions of camera preview) and add an transparent image with just a rectangle in its background. 要创建叠加层,请首先创建一个自定义视图(相机预览的完整尺寸),然后添加透明图像,背景中只有一个矩形。 use this view as overlay view. 将此视图用作叠加视图。

  myview =[[UIImageView alloc]init];
  myview.frame=CGRectMake(0, 0, 320, 431); 

 // why 431? bcoz height = height of device - height of tabbar present in the
   bottom for camera controls of picker
//for iphone 4 ,480-49

  myview.backgroundColor =[UIColor clearColor];
  myview.opaque = NO;
  myview.image =[UIImage imageNamed:@"A45Box.png"];
  myview.userInteractionEnabled =YES;

note that you create a background image appropriately (means dimensions). 请注意,您适当地创建了背景图像(表示尺寸)。 You can also draw rectangle programmatically but this is much easy way. 您也可以通过编程方式绘制矩形,但这是很简单的方法。

Secondly, talking about your cropping issue, you have to get your hands dirty....Try these links for help https://github.com/iosdeveloper/ImageCropper 其次,谈论您的裁剪问题,您必须动手做事......尝试以下链接以获取帮助https://github.com/iosdeveloper/ImageCropper

https://github.com/barrettj/BJImageCropper https://github.com/barrettj/BJImageCropper

https://github.com/ardalahmet/SSPhotoCropperViewController https://github.com/ardalahmet/SSPhotoCropperViewController

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

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