繁体   English   中英

使用SDWebImage下载大图像时应用崩溃

[英]App crash while downloading large images using SDWebImage

我正在使用SDWebImage从服务器异步下载图像。服务器上的某些图像大小为1772x1476像素。我正在UICollectionView上显示这些图像。 多次运行后,我收到内存警告和应用程序崩溃。有时是在第一次下载图像时发生的,有时是在我上下滚动集合视图时发生的。 这是我的代码-

我在我的x代码上收到警告,如下图

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];

[Mainimage sd_setImageWithURL:[NSURL URLWithString: Obj.imageYH] placeholderImage:[UIImage imageNamed:@""]];

   return cell;
}

在此处输入图片说明

您可以使用 :

[SDImageCache sharedImageCache] .config.shouldDecompressImages = NO; [[SDWebImageDownloader sharedDownloader] setShouldDecompressImages:NO];

在4.0-beta版本中

如果您的应用程序不需要显示完整尺寸的图像,则将其缩小并显示始终是一个好习惯。 这是做什么的例子。

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:url delegate:self options:0 success:^(UIImage *image) 
{
    //Scale down the image here and then set to your view.
}

它应该可以帮助您减少内存问题。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

            UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];

    [Mainimage setImageWithURL:[NSURL URLWithString: Obj.imageYH] placeholderImage:[UIImage imageNamed:@""]];

           return cell; 
}        

尝试这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM