gpt4 book ai didi

ios - UITableViewCell.imageView 给出内存警告?

转载 作者:行者123 更新时间:2023-11-29 03:06:10 25 4
gpt4 key购买 nike

我有一个 TableView Controller ,在该 Controller 中,我在每个单元格的 ImageView 中显示应用程序中录制的视频的缩略图。他们的高度都是90.5,确实没什么特别的。但是,加载此 View 会增加 40 MB 内存,这太多了。我不确定为什么会这样,有人可以提供一些见解吗?

了解缩略图作为二进制数据存储在视频对象中可能会很有用。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Video Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

self.tableView.rowHeight = 90.5;
cell.imageView.tag = indexPath.row;


Video *video = [self.videoArray objectAtIndex:indexPath.row];

cell.textLabel.text = [self.dateFormatter stringFromDate:video.createdAt];

cell.detailTextLabel.text = video.video_description;

cell.detailTextLabel.text = @"Tap on the thumbnail to add video information!";

cell.imageView.image = [UIImage imageWithData:video.thumbnail];

UIView *highlighted = [[UIView alloc]initWithFrame:cell.bounds];

[highlighted setBackgroundColor:[UIColor colorWithRed:0 green:122.0 / 255.0 blue:1.0 alpha:1.0]];

cell.selectedBackgroundView = highlighted;
cell.textLabel.highlightedTextColor = [UIColor whiteColor];
cell.detailTextLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.70];

return cell;
}

这是我获取缩略图的方法:

- (UIImage *)generateThumbnailAtURL:(NSURL *)URL {

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:URL options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
//generate.appliesPreferredTrackTransform = YES;
NSError *err = nil;
double halfTime = ((CMTimeGetSeconds(asset.duration)) / 2);
CMTime time = CMTimeMake(halfTime, 1);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:nil error:&err];
UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imgRef];
CGImageRelease(imgRef);

[thumbnail imageByScalingToSize:CGSizeMake(130,90) contentMode:UIViewContentModeScaleAspectFill];

return [UIImage imageWithData:UIImageJPEGRepresentation(thumbnail, 0.1)];
}

最佳答案

如果这是导致内存警告的行:

cell.imageView.image = [UIImage imageWithData:video.thumbnail];

你只需要有较低的分辨率,它用于细胞图像,高分辨率会像霰弹枪一样在内存中打洞。

关于ios - UITableViewCell.imageView 给出内存警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22748049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com