我有一个比较不同饰面的应用程序。
我有 2 个并排的图像视图,设置为 UIViewContentModeTopLeft
和 UIViewContentModeTopRight
.左边显示图像的左侧,右边显示图像的右侧,因此您可以无缝比较图像。您可以将任何饰面拖动到任一侧以查看它们。
我的问题是视网膜显示器以双倍大小显示图像,因此您只能在每个图像视图中看到一个顶部象限。如果我使用调整大小功能将图像大小减半,它可以工作,但非视网膜显示器在图像视图中显示小而完整的图像,而不仅仅是一半。
如果我运行调整大小函数并回读大小,我会得到这个,下面是我的调整大小函数:
2012-12-11 09:48:24.148 SRG[20290:C07] 设置图像宽度:700.000000 高度:525.000000 2012-12-11 09:48:24.198 SRG[20290:C07] 图像大小: {1400, 1050}
+ (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
CGImageRef imageRef = image.CGImage;
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);
CGContextConcatCTM(context, flipVertical);
// Draw into the context; this scales the image
CGContextDrawImage(context, newRect, imageRef);
// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGImageRelease(newImageRef);
UIGraphicsEndImageContext();
return newImage;
}
尝试拍摄图像并创建正常尺寸图像的两倍,并在项目中设置名称 "image"@2x.png
这样,Xcode 将自动将@2x图像用于视网膜显示设备,将常规image.png
用于非视网膜设备。或者,如果视网膜设备将您的图像变大,则将图像大小减半并将其设置为@2x,这应该可以解决问题。希望有帮助。