【发布时间】:2011-08-27 02:56:27
【问题描述】:
我无法从图像视图中裁剪图像,该图像在裁剪前已缩放和旋转。使用现有的裁剪方法。但它仅适用于固定的图像视图。希望代码会有所帮助。
【问题讨论】:
标签: iphone uiimageview crop image-rotation image-scaling
我无法从图像视图中裁剪图像,该图像在裁剪前已缩放和旋转。使用现有的裁剪方法。但它仅适用于固定的图像视图。希望代码会有所帮助。
【问题讨论】:
标签: iphone uiimageview crop image-rotation image-scaling
终于成功裁剪旋转缩放的图片了。
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);
谢谢。
【讨论】:
试试这个(如果你需要裁剪角落):
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];
只要增加半径,你就会把它变成圆形,或者沿着这条路走,你就会得到你的实际解决方案。:)
【讨论】:
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);
它用于裁剪特定的高度和宽度
【讨论】: