0

我正在执行以下操作来确定块期间下载图像的大小,然后我将相应地设置 uiimageview 的大小。

self.headerView 是 xib 中 uiimageview 的出口连接

  __weak  UIImageView *weakObj    =   self.headerView;

    [self.headerView setImageWithURLRequest:[NSMutableURLRequest requestWithURL:[NSURL URLWithString:fundraiserInfo.imageUrl]]
                           placeholderImage:nil
                                    success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
                                        NSLog(@"image is %@",NSStringFromCGSize(image.size));

                                        CGRect newFrame ;
                                        newFrame                    =   weakObj.frame;
                                        newFrame.size.width         =   image.size.width;
                                        newFrame.size.height        =   image.size.height;
                                        weakObj.frame               =   newFrame;


                                    }
                                    failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
                                        ;
                                    }
     ];

但是,当在模拟器(Device-Iphone)上运行应用程序时,我得到了

image is {300, 222}

但是,如果我使用模拟器 (Retina 3.5) 或 (Retina 4) 或者我在 iphone4 或 iphone 5 上安装应用程序,我会得到:

image is {150, 111}

为什么会这样。

4

2 回答 2

1

这是因为您正在下载的图像未被识别为“视网膜”图像,因此在视网膜设备上,它将显示为实际像素大小的一半。您可以通过读取文件名为“filenam@2x.jpg”的图像将图像指定为视网膜,或者您可以在创建时将 UIImage 的“缩放”值指定为 1.0(非视网膜)或 2.0(视网膜)

[UIImage imageWithData:scale:]
[UIImage imageWithCGImage:scale:orientation:]

如果您不提供比例值,则假定图像是您发现的适当分辨率。

于 2013-02-28T16:31:32.143 回答
0

原因是 UIImage 大小,从 iOS4 开始,返回的是点而不是像素。视网膜显示器上的哪个提供了您所看到的结果。来自苹果文档:

尺寸

图像的尺寸,考虑到方向。

@property(nonatomic, readonly) CGSize 大小

讨论 在 iOS 4.0 及更高版本中,该值反映了图像的逻辑大小,以磅为单位。在 iOS 3.x 及更早版本中,此值始终反映以像素为单位测量的图像尺寸。

于 2013-04-11T12:21:24.297 回答