向 tableview 单元格显示非常大的图像
Show very big size images to the tableview cell
我想在 uitableview
中显示用户保存在其 Document
目录中的一些图像。我使用下面的简单代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"uploadHistoryCellfa";
BRUploadHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[BRUploadHistoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
//Some Other assignemt to UILables Here...
[cell.imagePreview setImage:[UIImage imageWithContentsOfFile:myImagePathInDocument]];
//Some other configurations here ....
return cell;
}
我的问题是:
图像大小约为 11-25 MB。我将在每个单元格加载一张图像。我使用的这段代码是否可能导致内存泄漏或类似的事情?
如果一次只在屏幕上显示 1-2 个单元格,那么不会给您带来太大的麻烦。
因为 TableView 将使用新图像更新已创建的单元格的内容。 (双端队列可重用概念)
但更好的方法是先调整图像大小,然后再使用。
11-25 MB 实际上是一个大文件,如果您有 UITableView
,您将拥有超过 5 张图像,因此它将变为 11-25 (*5),因此您应该在将图像添加到 tableView 时调整它们的大小,但是如果你在显示的过程中调整它的大小,它会减慢你的应用程序。所以你的第一步是保存最大 1 mb 的调整大小的图像。
第二步是生成缩略图,然后在单元格上添加 thumbnail
图片。
第一个Link:Resize Image
第二个Link:Image Resizing Techniques
imageIO
对我来说是调整图像大小的最快方法,因为它使用 CPU 并且用户不会看到滚动缓慢的问题。
完成所有步骤后,不要忘记使用 foreground thread
和 main thread
在单元格上表示图像。
我想在 uitableview
中显示用户保存在其 Document
目录中的一些图像。我使用下面的简单代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"uploadHistoryCellfa";
BRUploadHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[BRUploadHistoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
//Some Other assignemt to UILables Here...
[cell.imagePreview setImage:[UIImage imageWithContentsOfFile:myImagePathInDocument]];
//Some other configurations here ....
return cell;
}
我的问题是:
图像大小约为 11-25 MB。我将在每个单元格加载一张图像。我使用的这段代码是否可能导致内存泄漏或类似的事情?
如果一次只在屏幕上显示 1-2 个单元格,那么不会给您带来太大的麻烦。 因为 TableView 将使用新图像更新已创建的单元格的内容。 (双端队列可重用概念)
但更好的方法是先调整图像大小,然后再使用。
11-25 MB 实际上是一个大文件,如果您有 UITableView
,您将拥有超过 5 张图像,因此它将变为 11-25 (*5),因此您应该在将图像添加到 tableView 时调整它们的大小,但是如果你在显示的过程中调整它的大小,它会减慢你的应用程序。所以你的第一步是保存最大 1 mb 的调整大小的图像。
第二步是生成缩略图,然后在单元格上添加 thumbnail
图片。
第一个Link:Resize Image
第二个Link:Image Resizing Techniques
imageIO
对我来说是调整图像大小的最快方法,因为它使用 CPU 并且用户不会看到滚动缓慢的问题。
完成所有步骤后,不要忘记使用 foreground thread
和 main thread
在单元格上表示图像。