【发布时间】:2015-01-15 07:01:44
【问题描述】:
当从中心裁剪图像时,裁剪图像将采用源图像的纵横比,但根据我的要求,纵横比会随着新的裁剪尺寸而变化。
我想获得具有新纵横比的图像的确切中心部分。例如,大图像的大小为 (320*480),然后我想裁剪大小为 (100,100) 的图像的中心部分,纵横比也将是100*100,无需外白或外黑,画质高。
裁剪功能:
- (UIImage *)cropImage:(UIImage*)image andFrame:(CGRect)rect {
//Note : rec is nothing but the image frame which u want to crop exactly.
rect = CGRectMake(rect.origin.x*image.scale,
rect.origin.y*image.scale,
rect.size.width*image.scale,
rect.size.height*image.scale);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
UIImage *result = [UIImage imageWithCGImage:imageRef
scale:image.scale
orientation:image.imageOrientation];
CGImageRelease(imageRef);
return result;
}
请帮助我。
【问题讨论】:
-
保留 Xcode 标签。这个问题根本与 Xcode IDE 无关。而且,你的代码在哪里?
-
我已经用裁剪功能更新了我的问题
-
任何人帮助我......我的项目尝试面对形状图像裁剪但不裁剪目标c
标签: ios objective-c image