如何裁剪缩放、旋转的图像视图的某些部分

发布于 2024-11-07 13:25:40 字数 70 浏览 3 评论 0原文

我无法从图像视图中裁剪图像,该图像在裁剪之前已缩放和旋转。使用现有的裁剪方法。但它仅适用于固定的图像视图。希望代码会有所帮助。

I am unable to crop he image from image view, which is scaled and rotated before cropping. used existing cropping methods.but its applicable only for image-view which is fixed.Hope code will helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小草泠泠 2024-11-14 13:25:40

最终成功裁剪旋转缩放图像。

1)需要裁剪整个缩放或旋转的图像。

2)从裁剪图像中裁剪矩形。您将获得最终缩放或旋转的裁剪图像。

我发布示例代码,它可能对其他人有帮助。

UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


CGRect rect = CGRectMake(100,100 ,200, 200);//Rect we need from scaled or rotated image.
CGImageRef cropped = CGImageCreateWithImageInRect(viewImage.CGImage, rect);
UIImage *img =  [UIImage imageWithCGImage:cropped]; 
CGImageRelease(cropped);

谢谢。

Finally succeeded cropping rotated scaled image.

1) Need to crop the entire scaled or rotated image.

2)crop the rect from cropped Image. you will get final scaled or rotated cropped image.

Im posting sample code , it may helpful for others.

UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


CGRect rect = CGRectMake(100,100 ,200, 200);//Rect we need from scaled or rotated image.
CGImageRef cropped = CGImageCreateWithImageInRect(viewImage.CGImage, rect);
UIImage *img =  [UIImage imageWithCGImage:cropped]; 
CGImageRelease(cropped);

Thanks.

孤凫 2024-11-14 13:25:40

试试这个(如果你需要裁剪角落):

UIImageView *imageSubview = [[UIImageView alloc] initWithFrame:CGRectMake(50.0f, 5.0f,80.0f, 60.0f)];

[imageSubview setImage:actualImage]; 
[imageSubview setContentMode:UIViewContentModeScaleToFill];
[imageSubview.layer setCornerRadius:10.0];
[imageSubview.layer setMasksToBounds:YES];
[cell addSubview:imageSubview];

只需增加半径,你就会使它成为圆形,或者沿着这条路径走,你会得到你的实际解决方案。:)

Try This(if you need to crop the corners):

UIImageView *imageSubview = [[UIImageView alloc] initWithFrame:CGRectMake(50.0f, 5.0f,80.0f, 60.0f)];

[imageSubview setImage:actualImage]; 
[imageSubview setContentMode:UIViewContentModeScaleToFill];
[imageSubview.layer setCornerRadius:10.0];
[imageSubview.layer setMasksToBounds:YES];
[cell addSubview:imageSubview];

Just increase the radius and you will make it circle, or walk on this path you'll get your actual solution.:)

七婞 2024-11-14 13:25:40
UIImage *myImage = [UIImage imageNamed:@"photo.png"];

CGRect cropRect = CGRectMake(0.0, 0.0, 320.0, 44.0));
CGImageRef croppedImage = CGImageCreateWithImageInRect([myImage CGImage], cropRect);

UIImageView *myImageView = [[UIImageView alloc] initWithFrame:cropRect];
[myImageView setImage:[UIImage imageWithCGImage:croppedImage]]; 

CGImageRelease(croppedImage);

用于裁剪特定的高度和宽度

UIImage *myImage = [UIImage imageNamed:@"photo.png"];

CGRect cropRect = CGRectMake(0.0, 0.0, 320.0, 44.0));
CGImageRef croppedImage = CGImageCreateWithImageInRect([myImage CGImage], cropRect);

UIImageView *myImageView = [[UIImageView alloc] initWithFrame:cropRect];
[myImageView setImage:[UIImage imageWithCGImage:croppedImage]]; 

CGImageRelease(croppedImage);

its for cropping particular height and width

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文