【问题标题】:UITableViewCell with UIImage scaling performance具有 UIImage 缩放性能的 UITableViewCell
【发布时间】:2012-12-29 18:04:53
【问题描述】:

UITableViewCell 有 UIImage 要显示在其中。

图像从服务器获取,并作为 NSData 存储在 NSDictionary 中。

使用 UIImageGraphicsBeginImageContext 为非视网膜设备调整此图像的大小,如下所示。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

            static NSString *cellID=@"Cell";
            UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            NSDictionary *myDictionary=[self.tableObject objectAtIndex:indexPath.row];
            NSData *imgData=[myDictionary objectForKey:@"icon"];
            UIImage *img=[UIImage imageWithData:imgData];
            if(isRetina]){
                cell.iconImageView.image=img;
            }else{
                CGRect imgRect=CGRectMake(0, 0, img.size.width/2.0, img.size.height/2.0);
                UIGraphicsBeginImageContext(imgRect.size);
                [img drawInRect:imgRect];
                UIImage *newImg=UIGraphicsGetImageFromCurrentImageContext();
                UIGraphicsEndImageContext();
                cell.iconImageView.image=newImg;
            }
}

会是更好的方法和更少的内存密集型还是应该将其存储在磁盘中,然后从中访问图像并将其分配给 cell.iconImageView.image;

【问题讨论】:

    标签: ios uitableview uiimageview uiimage


    【解决方案1】:

    下载时将其写入磁盘。

    这样,操作系统可以懒惰地读取数据,缓存它,而你的内存中不会一直有图像数据

    【讨论】:

    • 即使我也有同感,但我担心从磁盘中读取图像的性能 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath跨度>
    • 但是,从磁盘读取它比在应用程序中读取它需要相当长的时间。本身使用 [UIImage imageNamed:@"a.png"];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 2016-05-07
    • 2011-08-28
    相关资源
    最近更新 更多