我正在使用 SDWebImage(2.7.3 框架)并且收到损坏的图像,我无法完全理解问题所在。如果是代码(内存...)

(笔记:
使用 SDWebImage 项目而不是框架时,我遇到了同样的错误。
我正在实现“自动释放”和其他类型的内存管理。
此问题在设备(iPad)上出现,但在模拟器中不出现)

    __block CALayer *layerCover = [[CALayer alloc] init];
    layerCover.frame = CGRectMake(3, 3, COVER_WIDTH_IPAD_SMALL, COVER_HEIGHT_IPAD_SMALL);
    [btn.layer addSublayer:layerCover];

    [_scroll addSubview:btn];
    [btn release];

    //request or load Vods Images
    [[SDWebImageManager sharedManager] downloadWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@M", vod.cover]]
                                              delegate:self options:SDWebImageProgressiveDownload success:^(UIImage *image, BOOL cached) {
                                                  if (image) {
                                                      layerCover.contents = (id)image.CGImage;
                                                  }
                                                  [layerCover release];
                                              } failure:^(NSError *error) {
                                                  [layerCover release];
                                              }];

//另一种
UIImage * imageTv = [UIImage imageNamed:@"bgDefaultTvImage.png"];
UIImageView * bgTvImage = [[UIImageView alloc] initWithFrame:CGRectMake(startX, 20, imageTv.size.width, imageTv.size.height)];
[bgTvImage setImage:imageTv];

CGFloat sizeWithIcon = imageTv.size.width;
CGFloat sizeHeightIcon = imageTv.size.height;
__block UIImageView * bgImageicon = [[UIImageView alloc] initWithFrame:CGRectMake((bgTvImage.frame.size.width-sizeWithIcon)/2,
                                                                          (bgTvImage.frame.size.height-sizeHeightIcon)/2,
                                                                          sizeWithIcon,
                                                                          sizeHeightIcon)];
bgImageicon.contentMode = UIViewContentModeScaleAspectFit;
[bgTvImage addSubview:bgImageicon];
[tvTopView addSubview:bgTvImage];

/*
 * Request ProgramImage
 */
[[SDWebImageManager sharedManager] downloadWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@&width=300",program.ProgramImage.imageURL]]
                                              delegate:self options:SDWebImageProgressiveDownload success:^(UIImage *image, BOOL cached) {
                                                  if (image) {
                                                      iconCanal = image;
                                                      [bgImageicon setImage:iconCanal];
                                                  }
                                                  [bgImageicon release];
                                              }failure:^(NSError *error) {
                                                  [bgImageicon release];
                                              }];

Xcode 日志:
<Error>: ImageIO: JPEG Corrupt JPEG data: bad Huffman code
<Error>: ImageIO: JPEG Corrupt JPEG data: premature end of data segment

最佳答案

好像是 SDWebImageProgressiveDownload 标志的问题。尝试禁用它,例如像这样:

[[SDWebImageManager sharedManager] downloadWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@&width=300",program.ProgramImage.imageURL]]
                                          delegate:self options:0 success:^(UIImage *image, BOOL cached) {
                                              if (image) {
                                                  iconCanal = image;
                                                  [bgImageicon setImage:iconCanal];
                                              }
                                              [bgImageicon release];
                                          }failure:^(NSError *error) {
                                              [bgImageicon release];
                                          }];

10-08 06:13