在我的iPhone应用程序中,我用相机拍照,然后我想将其调整为290*390像素.我正在使用此方法调整图像大小:
UIImage *newImage = [image _imageScaledToSize:CGSizeMake(290, 390)
interpolationQuality:1];
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但它是一个未记录的功能,所以我不能再使用iPhone OS4了.
那么...调整UIImage大小的最简单方法是什么?
可能重复:
使用宽高比调整UIImage的大小?
下面这段代码正在完美地调整图像大小,但问题是它会混淆纵横比(导致图像偏斜).有什么指针吗?
// Change image resolution (auto-resize to fit)
+ (UIImage *)scaleImage:(UIImage*)image toResolution:(int)resolution {
CGImageRef imgRef = [image CGImage];
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGRect bounds = CGRectMake(0, 0, width, height);
//if already at the minimum resolution, return the orginal image, otherwise scale
if (width <= resolution && height <= resolution) {
return image;
} else {
CGFloat ratio = width/height;
if (ratio > 1) {
bounds.size.width = resolution;
bounds.size.height = bounds.size.width / ratio;
} else …Run Code Online (Sandbox Code Playgroud)