【问题标题】:Retina display, ImageView showing wrong size image set to UIViewContentModeTopRight视网膜显示,ImageView 显示错误大小的图像设置为 UIViewContentModeTopRight
【发布时间】:2012-12-11 15:01:01
【问题描述】:

我有一个可以比较不同饰面的应用。

我有 2 个并排的图像视图,设置为 UIViewContentModeTopLeftUIViewContentModeTopRight。左侧显示图像的左侧,右侧显示图像的右侧,因此您可以无缝比较图像。您可以将任何饰面拖动到任一侧以查看它们。

我的问题是视网膜显示器以双倍尺寸显示图像,因此您只能在每个图像视图中看到顶部象限。如果我使用调整大小功能将图像大小减半,它可以工作,但非视网膜显示器会在图像视图中显示小而完整的图像,而不仅仅是一半。

如果我运行调整大小函数并读回大小,我会得到这个,下面是我的调整大小函数:

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;
}

【问题讨论】:

  • 所以你正在画两张并排的图像?您实际尝试绘制它们的尺寸是多少?
  • 左半部分是 350 x 525,右半部分是 iPad 上的 350 x 525,图像整体应该是 700x525,但只有一半显示在应用程序的这个分屏部分。当设备是 iPhone 时,一切都会缩小。

标签: objective-c uiimageview retina-display


【解决方案1】:

尝试获取图像并创建两倍于正常大小的图像并将其设置在您的项目中,名称为"image"@2x.png 这样,xcode 将自动将@2x 图像用于视网膜显示设备,而常规image.png 用于非视网膜设备。或者,如果视网膜设备使您的图像变大,则将图像缩小一半并将其设置为@2x,这应该可以解决问题。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多