Objective-C iOS裁剪图像使用缩放? [英] Objective-C iOS Crop Image Using Zoom?
问题描述
我正在尝试使用此代码来允许用户在我的应用中缩放和裁剪图像:
https://github.com/iosdeveloper/ImageCropper/tree/master/Classes/ImageCropper
I am trying to use this code to allow users to zoom and crop their images in my app: https://github.com/iosdeveloper/ImageCropper/tree/master/Classes/ImageCropper
code snippet
code snippet
float zoomScale = 1.0 / [scrollView zoomScale];
CGRect rect;
rect.origin.x = [scrollView contentOffset].x * zoomScale;
rect.origin.y = [scrollView contentOffset].y * zoomScale;
rect.size.width = [scrollView bounds].size.width * zoomScale;
rect.size.height = [scrollView bounds].size.height * zoomScale;
CGImageRef cr = CGImageCreateWithImageInRect([[imageView image] CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:cr];
CGImageRelease(cr);
[delegate imageCropper:self didFinishCroppingWithImage:cropped];
但它没有考虑旋转的图像(我猜这是iPhone上的某种元数据)图片)。我不想让用户绘制一个矩形来裁剪,因为我更喜欢这个界面。
But it does not take into account images being rotated (I guess it's some sort of metadata on the iPhone images). I do not want to have users draw a rectangle to crop as I much prefer this interface.
有人能告诉我如何让它不旋转我的图像吗?
Can someone tell me how to make it not rotate my images?
我在iOS 5& 6如果有帮助的话。
I am building in iOS 5 & 6 if that helps.
此外,这在Game Center应用程序中很好地完成了上传你的个人资料图片。有人知道我在哪里可以找到代码吗?
Also, this is done nicely in the Game Center application for uploading your profile picture. Anyone know where I can find the code for that?
推荐答案
我在这里找到了一个帮助我做我想要的答案
iOS:裁剪从具有叠加层的UIImagePickerController摄像头抓取的静止图像
I found an answer here that helped me do what I wanted iOS: Cropping a still image grabbed from a UIImagePickerController camera with overlay
感兴趣的代码片段
float zoomScale = 1.0 / [scrollView zoomScale];
CGRect rect;
NSLog(@"contentOffset is :%f,%f",[scrollView contentOffset].x,[scrollView contentOffset].y);
rect.origin.x = fabsf([scrollView contentOffset].x * zoomScale);
rect.origin.y = fabsf([scrollView contentOffset].y * zoomScale);
rect.size.width = fabsf([scrollView bounds].size.width * zoomScale);
rect.size.height = fabsf([scrollView bounds].size.height * zoomScale);
UIGraphicsBeginImageContextWithOptions( CGSizeMake( rect.size.width,
rect.size.height),
NO,
0.);
[[imageView image] drawAtPoint:CGPointMake( -rect.origin.x, -rect.origin.y)
blendMode:kCGBlendModeCopy
alpha:1.];
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这篇关于Objective-C iOS裁剪图像使用缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!