gpt4 book ai didi

iphone - 如何裁剪 objective-c 中的图像?

转载 作者:可可西里 更新时间:2023-11-01 03:02:15 25 4
gpt4 key购买 nike

用户可以更改在编辑屏幕中默认显示的 cropbox 大小。我尝试使用以下代码:

- (UIImage *)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect {

CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}

但是它裁剪了固定区域。如何裁剪用户选择的区域?

最佳答案

获取裁剪图像:

UIImage *croppedImg = nil;
CGRect cropRect = CGRectMake("AS YOu Need"); //set your rect size.
croppedImg = [self croppIngimageByImageName:self.imageView.image toRect:cropRect];

使用以下代码调用 croppIngimageByImageName:toRect: 返回 UIImage 的方法(具有特定大小的图像)

- (UIImage *)croppIngimageByImageName:(UIImage *)imageToCrop toRect:(CGRect)rect
{
//CGRect CropRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height+15);

CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

return cropped;
}

关于iphone - 如何裁剪 objective-c 中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18205672/

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