简体   繁体   中英

SDWebImage corrupt images

I'm using SDWebImage (2.7.3 framework) and I receive corrupt images, I can't understand exactly the problem. If is the code (memory...)

(notes: I get the same error using the SDWebImage project instead of the framework. I'm implementing "autorelease" and other kinds of memory management. This problem arises on devices (iPad), but not in the simulator)

在此输入图像描述在此输入图像描述

    __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];
                                              }];

//another kind

在此输入图像描述

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 logs:

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

It seems to be the problem of SDWebImageProgressiveDownload flag. Try to disable it, for example like this:

[[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];
                                          }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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