gpt4 book ai didi

ios - 使用缩放的 Objective-C iOS 裁剪图像?

转载 作者:可可西里 更新时间:2023-11-01 05:45:55 28 4
gpt4 key购买 nike

我正在尝试使用此代码允许用户在我的应用中缩放和裁剪他们的图像: https://github.com/iosdeveloper/ImageCropper/tree/master/Classes/ImageCropper

代码片段

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 图像上的某种元数据)。我不想让用户画一个矩形来裁剪,因为我更喜欢这个界面。

谁能告诉我如何让它不旋转我的图像?

如果有帮助,我将在 iOS 5 和 6 中构建。

[编辑] 此外,这在 Game Center 应用程序中可以很好地上传您的个人资料图片。有人知道我在哪里可以找到它的代码吗?

最佳答案

我在这里找到了帮助我做我想做的事情的答案 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();

关于ios - 使用缩放的 Objective-C iOS 裁剪图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13784182/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com