Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.

Related tags

GIF YYImage
Overview

YYImage

License MIT  Carthage compatible  CocoaPods  CocoaPods  Support  Build Status

Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.
(It's a component of YYKit)

niconiconi~

Features

  • Display/encode/decode animated image with these types:
        WebP, APNG, GIF.
  • Display/encode/decode still image with these types:
        WebP, PNG, GIF, JPEG, JP2, TIFF, BMP, ICO, ICNS.
  • Baseline/progressive/interlaced image decode with these types:
        PNG, GIF, JPEG, BMP.
  • Display frame based image animation and sprite sheet animation.
  • Dynamic memory buffer for lower memory usage.
  • Fully compatible with UIImage and UIImageView class.
  • Extendable protocol for custom image animation.
  • Fully documented.

Usage

Display animated image

// File: [email protected]
UIImage *image = [YYImage imageNamed:@"ani.gif"];
UIImageView *imageView = [[YYAnimatedImageView alloc] initWithImage:image];
[self.view addSubview:imageView];

Display frame animation

// Files: frame1.png, frame2.png, frame3.png
NSArray *paths = @[@"/ani/frame1.png", @"/ani/frame2.png", @"/ani/frame3.png"];
NSArray *times = @[@0.1, @0.2, @0.1];
UIImage *image = [YYFrameImage alloc] initWithImagePaths:paths frameDurations:times repeats:YES];
UIImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];
[self.view addSubview:imageView];

Display sprite sheet animation

// 8 * 12 sprites in a single sheet image
UIImage *spriteSheet = [UIImage imageNamed:@"sprite-sheet"];
NSMutableArray *contentRects = [NSMutableArray new];
NSMutableArray *durations = [NSMutableArray new];
for (int j = 0; j < 12; j++) {
   for (int i = 0; i < 8; i++) {
       CGRect rect;
       rect.size = CGSizeMake(img.size.width / 8, img.size.height / 12);
       rect.origin.x = img.size.width / 8 * i;
       rect.origin.y = img.size.height / 12 * j;
       [contentRects addObject:[NSValue valueWithCGRect:rect]];
       [durations addObject:@(1 / 60.0)];
   }
}
YYSpriteSheetImage *sprite;
sprite = [[YYSpriteSheetImage alloc] initWithSpriteSheetImage:img
                                                contentRects:contentRects
                                              frameDurations:durations
                                                   loopCount:0];
YYAnimatedImageView *imageView = [YYAnimatedImageView new];
imageView.size = CGSizeMake(img.size.width / 8, img.size.height / 12);
imageView.image = sprite;
[self.view addSubview:imageView];

Animation control

YYAnimatedImageView *imageView = ...;
// pause:
[imageView stopAnimating];
// play:
[imageView startAnimating];
// set frame index:
imageView.currentAnimatedImageIndex = 12;
// get current status
image.currentIsPlayingAnimation;

Image decoder

// Decode single frame:
NSData *data = [NSData dataWithContentsOfFile:@"/tmp/image.webp"];
YYImageDecoder *decoder = [YYImageDecoder decoderWithData:data scale:2.0];
UIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;
	
// Progressive:
NSMutableData *data = [NSMutableData new];
YYImageDecoder *decoder = [[YYImageDecoder alloc] initWithScale:2.0];
while(newDataArrived) {
   [data appendData:newData];
   [decoder updateData:data final:NO];
   if (decoder.frameCount > 0) {
       UIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;
       // progressive display...
   }
}
[decoder updateData:data final:YES];
UIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;
// final display...

Image encoder

// Encode still image:
YYImageEncoder *jpegEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeJPEG];
jpegEncoder.quality = 0.9;
[jpegEncoder addImage:image duration:0];
NSData jpegData = [jpegEncoder encode];
 
// Encode animated image:
YYImageEncoder *webpEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeWebP];
webpEncoder.loopCount = 5;
[webpEncoder addImage:image0 duration:0.1];
[webpEncoder addImage:image1 duration:0.15];
[webpEncoder addImage:image2 duration:0.2];
NSData webpData = [webpEncoder encode];

Image type detection

// Get image type from image data
YYImageType type = YYImageDetectType(data); 
if (type == YYImageTypePNG) ...

Installation

CocoaPods

  1. Update cocoapods to the latest version.
  2. Add pod 'YYImage' to your Podfile.
  3. Run pod install or pod update.
  4. Import <YYImage/YYImage.h>.
  5. Notice: it doesn't include WebP subspec by default, if you want to support WebP format, you may add pod 'YYImage/WebP' to your Podfile.

Carthage

  1. Add github "ibireme/YYImage" to your Cartfile.
  2. Run carthage update --platform ios and add the framework to your project.
  3. Import <YYImage/YYImage.h>.
  4. Notice: carthage framework doesn't include WebP component, if you want to support WebP format, use CocoaPods or install manually.

Manually

  1. Download all the files in the YYImage subdirectory.
  2. Add the source files to your Xcode project.
  3. Link with required frameworks:
    • UIKit
    • CoreFoundation
    • QuartzCore
    • AssetsLibrary
    • ImageIO
    • Accelerate
    • MobileCoreServices
    • libz
  4. Import YYImage.h.
  5. Notice: if you want to support WebP format, you may add Vendor/WebP.framework(static library) to your Xcode project.

FAQ

Q: Why I can't display WebP image?

A: Make sure you added the WebP.framework in your project. You may call YYImageWebPAvailable() to check whether the WebP subspec is installed correctly.

Q: Why I can't play APNG animation?

A: You should disable the Compress PNG Files and Remove Text Metadata From PNG Files in your project's build settings. Or you can rename your APNG file's extension name with apng.

Documentation

Full API documentation is available on CocoaDocs.
You can also install documentation locally using appledoc.

Requirements

This library requires iOS 6.0+ and Xcode 8.0+.

License

YYImage is provided under the MIT license. See LICENSE file for details.



中文介绍

YYImage: 功能强大的 iOS 图像框架。
(该项目是 YYKit 组件之一)

niconiconi~

特性

  • 支持以下类型动画图像的播放/编码/解码:
        WebP, APNG, GIF。
  • 支持以下类型静态图像的显示/编码/解码:
        WebP, PNG, GIF, JPEG, JP2, TIFF, BMP, ICO, ICNS。
  • 支持以下类型图片的渐进式/逐行扫描/隔行扫描解码:
        PNG, GIF, JPEG, BMP。
  • 支持多张图片构成的帧动画播放,支持单张图片的 sprite sheet 动画。
  • 高效的动态内存缓存管理,以保证高性能低内存的动画播放。
  • 完全兼容 UIImage 和 UIImageView,使用方便。
  • 保留可扩展的接口,以支持自定义动画。
  • 每个类和方法都有完善的文档注释。

用法

显示动画类型的图片

// 文件: [email protected]
UIImage *image = [YYImage imageNamed:@"ani.gif"];
UIImageView *imageView = [[YYAnimatedImageView alloc] initWithImage:image];
[self.view addSubview:imageView];

播放帧动画

// 文件: frame1.png, frame2.png, frame3.png
NSArray *paths = @[@"/ani/frame1.png", @"/ani/frame2.png", @"/ani/frame3.png"];
NSArray *times = @[@0.1, @0.2, @0.1];
UIImage *image = [YYFrameImage alloc] initWithImagePaths:paths frameDurations:times repeats:YES];
UIImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];
[self.view addSubview:imageView];

播放 sprite sheet 动画

// 8 * 12 sprites in a single sheet image
UIImage *spriteSheet = [UIImage imageNamed:@"sprite-sheet"];
NSMutableArray *contentRects = [NSMutableArray new];
NSMutableArray *durations = [NSMutableArray new];
for (int j = 0; j < 12; j++) {
   for (int i = 0; i < 8; i++) {
       CGRect rect;
       rect.size = CGSizeMake(img.size.width / 8, img.size.height / 12);
       rect.origin.x = img.size.width / 8 * i;
       rect.origin.y = img.size.height / 12 * j;
       [contentRects addObject:[NSValue valueWithCGRect:rect]];
       [durations addObject:@(1 / 60.0)];
   }
}
YYSpriteSheetImage *sprite;
sprite = [[YYSpriteSheetImage alloc] initWithSpriteSheetImage:img
                                                contentRects:contentRects
                                              frameDurations:durations
                                                   loopCount:0];
YYAnimatedImageView *imageView = [YYAnimatedImageView new];
imageView.size = CGSizeMake(img.size.width / 8, img.size.height / 12);
imageView.image = sprite;
[self.view addSubview:imageView];

动画播放控制

YYAnimatedImageView *imageView = ...;
// 暂停:
[imageView stopAnimating];
// 播放:
[imageView startAnimating];
// 设置播放进度:
imageView.currentAnimatedImageIndex = 12;
// 获取播放状态:
image.currentIsPlayingAnimation;
//上面两个属性都支持 KVO。

图片解码

// 解码单帧图片:
NSData *data = [NSData dataWithContentsOfFile:@"/tmp/image.webp"];
YYImageDecoder *decoder = [YYImageDecoder decoderWithData:data scale:2.0];
UIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;
	
// 渐进式图片解码 (可用于图片下载显示):
NSMutableData *data = [NSMutableData new];
YYImageDecoder *decoder = [[YYImageDecoder alloc] initWithScale:2.0];
while(newDataArrived) {
   [data appendData:newData];
   [decoder updateData:data final:NO];
   if (decoder.frameCount > 0) {
       UIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;
       // progressive display...
   }
}
[decoder updateData:data final:YES];
UIImage image = [decoder frameAtIndex:0 decodeForDisplay:YES].image;
// final display...

图片编码

// 编码静态图 (支持各种常见图片格式):
YYImageEncoder *jpegEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeJPEG];
jpegEncoder.quality = 0.9;
[jpegEncoder addImage:image duration:0];
NSData jpegData = [jpegEncoder encode];
 
// 编码动态图 (支持 GIF/APNG/WebP):
YYImageEncoder *webpEncoder = [[YYImageEncoder alloc] initWithType:YYImageTypeWebP];
webpEncoder.loopCount = 5;
[webpEncoder addImage:image0 duration:0.1];
[webpEncoder addImage:image1 duration:0.15];
[webpEncoder addImage:image2 duration:0.2];
NSData webpData = [webpEncoder encode];

图片类型探测

// 获取图片类型
YYImageType type = YYImageDetectType(data); 
if (type == YYImageTypePNG) ...

安装

CocoaPods

  1. 将 cocoapods 更新至最新版本.
  2. 在 Podfile 中添加 pod 'YYImage'
  3. 执行 pod installpod update
  4. 导入 <YYImage/YYImage.h>。
  5. 注意:pod 配置并没有包含 WebP 组件, 如果你需要支持 WebP,可以在 Podfile 中添加 pod 'YYImage/WebP'

Carthage

  1. 在 Cartfile 中添加 github "ibireme/YYImage"
  2. 执行 carthage update --platform ios 并将生成的 framework 添加到你的工程。
  3. 导入 <YYImage/YYImage.h>。
  4. 注意:carthage framework 并没有包含 WebP 组件。如果你需要支持 WebP,可以用 CocoaPods 安装,或者手动安装。

手动安装

  1. 下载 YYImage 文件夹内的所有内容。
  2. 将 YYImage 内的源文件添加(拖放)到你的工程。
  3. 链接以下 frameworks:
    • UIKit
    • CoreFoundation
    • QuartzCore
    • AssetsLibrary
    • ImageIO
    • Accelerate
    • MobileCoreServices
    • libz
  4. 导入 YYImage.h
  5. 注意:如果你需要支持 WebP,可以将 Vendor/WebP.framework(静态库) 加入你的工程。

常见问题

Q: 为什么我不能显示 WebP 图片?

A: 确保 WebP.framework 已经被添加到你的工程内了。你可以调用 YYImageWebPAvailable() 来检查一下 WebP 组件是否被正确安装。

Q: 为什么我不能播放 APNG 动画?

A: 你应该禁用 Build Settings 中的 Compress PNG FilesRemove Text Metadata From PNG Files. 或者你也可以把 APNG 文件的扩展名改为apng.

文档

你可以在 CocoaDocs 查看在线 API 文档,也可以用 appledoc 本地生成文档。

系统要求

该项目最低支持 iOS 6.0Xcode 8.0

许可证

YYImage 使用 MIT 许可证,详情见 LICENSE 文件。

相关链接

移动端图片格式调研

iOS 处理图片的一些小 Tip

Comments
  • issue:Multiple locks on web thread not allowed!

    issue:Multiple locks on web thread not allowed!

    求助:加载图片进度条展示使用UCZProgressView,使用后会出现WTFCrash 2016-08-12 14:11:46.978 mode[17853:573412] bool _WebTryThreadLock(bool), 0x7fc0828f7300: Multiple locks on web thread not allowed! Please file a bug. Crashing now... 1 0x10aabe34e WebRunLoopLock(__CFRunLoopObserver*, unsigned long, void*) 2 0x1066acc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ 3 0x1066acba7 __CFRunLoopDoObservers 4 0x1066a26c4 __CFRunLoopRun 5 0x1066a20f8 CFRunLoopRunSpecific 6 0x10aabe325 RunWebThread(void*) 7 0x10773599d _pthread_body 8 0x10773591a _pthread_body 9 0x107733351 thread_start screen shot 2016-08-12 at 2 24 41 pm screen shot 2016-08-12 at 2 23 00 pm

    opened by cloudhm 3
  • Orientation为右的UIImage编码错误

    Orientation为右的UIImage编码错误

        NSData *data = [YYImageEncoder encodeImage:image type:YYImageTypeWebP quality:0.75];
    

    用以上代码对一张 Orientation 为右的 UIImage 进行编码时,发现编码后得到图片是错误的,如下图。 img_0492

    定位到是 YYImageCoder.m 下 YYCGImageCreateAffineTransformCopy 的问题。水平有限,这个地方看不懂,提上来请大神修复。

    opened by jayi 3
  • Make WebP Format Work With XCode 11.2.2 Build (cocoapods installation)

    Make WebP Format Work With XCode 11.2.2 Build (cocoapods installation)

    With CocaoPods Project , XCode 11.2.2 Build. If using webp, YYIMAGE_WEBP_ENABLED always equal zero. So App don't play animated web image any more. I just changed webp ~> WebP to make it work again

    opened by duyhungtnn 2
  • BAD_ACCESS on YYImageCoder.m

    BAD_ACCESS on YYImageCoder.m

    When I call the method YYCGImageCreateEncodedWebPData(lista[i].cgImage!, false, 0, 0, YYImagePreset.default) and step an image with transparency as parameter, the YYImageCoder.m returns me a BAD_ACCESS error, more precisely on the line:   if (! WebPPictureImportRGBA (& picture, buffer.data, (int) buffer.rowBytes)) goto fail;

    Can someone help me?

    opened by Lailan 2
  • Do not let Xcode compressed APNG files

    Do not let Xcode compressed APNG files

    In README, it may worth to note that for APNG we need to disable Compressing PNG in Xcode, which is enabled by default. It took me a couple of hours to figure out what's wrong.

    opened by superarts 2
  • Wrong code in YYImageCoder.m

    Wrong code in YYImageCoder.m

    The code below in YYImageCode.m at line 1405-1415 The buffer named "tmp" is never used, please fix. And the code segment is never run...

    ` if (iter.x_offset != 0 || iter.y_offset != 0) {

    void *tmp = calloc(1, destLength);
    
    if (tmp) {
    
        vImage_Buffer src = {destBytes, canvasHeight, canvasWidth, bytesPerRow};
    
        vImage_Buffer dest = {destBytes, canvasHeight, canvasWidth, bytesPerRow};
    
        vImage_CGAffineTransform transform = {1, 0, 0, 1, iter.x_offset, -iter.y_offset};
    
        uint8_t backColor[4] = {0};
    
        vImageAffineWarpCG_ARGB8888(&src, &dest, NULL, &transform, backColor, kvImageBackgroundColorFill);
    
        memcpy(destBytes, tmp, destLength);
    
        free(tmp);
    
    }
    

    }

    `

    opened by wysaid 2
  • 项目里所有的 webp 解析出来的 image均为空(nil), 同 #11,但原因似乎不同, android 使用 Fresco解析正常

    项目里所有的 webp 解析出来的 image均为空(nil), 同 #11,但原因似乎不同, android 使用 Fresco解析正常

    notdisplay_1.webp.zip

    RT, 我们服务器使用的图片是七牛那边的,转换为webp格式的,之前一直使用 SDWebImage 可以正常显示。 尝试使用 YYImage 或者直接使用 YYWebImage 均如此。

    1. 我看了#11,并且 在引用到了VP8_STATUS_NOT_ENOUGH_DATA做判断的地方都打了断点,并没有走到: YYCGImageCreateWithWebPData 和 _newUnblendedImageAtIndex
    2. YYImageDecoder 通过 _frameAtIndex 获取到的 YYImageFrame 为 nil, 跟进去看到 frame.blendFromIndex = 1,同时frame.index = 0,导致不会走以下循环
    for (uint32_t i = (uint32_t)frame.blendFromIndex; i <= (uint32_t)frame.index; i++) {
                    if (i == frame.index) {
                        if (!imageRef) imageRef = [self _newBlendedImageWithFrame:frame];
                    } else {
                        [self _blendImageWithFrame:_frames[i]];
                    }
                }
    

    最终走到空的 imageRef

    if (!imageRef) return nil;
    
    1. 另外尝试了服务器提供的 webp 格式的动图,一样无法解析,没有跟进,推测跟静态 webp 解析失败有关
    2. 同样的静态 webp 和动态 webp,android 那边使用 facebook 开源的Fresco均能正常解析显示
    opened by btxkenshin 2
  • Alamofire upload

    Alamofire upload

    I tried uploading an webp image with Alamofire like that

    Alamofire.upload(
            .POST,
        "https://example.com/upload",
        multipartFormData: { multipartFormData in
            multipartFormData.appendBodyPart(data: data, name: "image", fileName: "file.webp", mimeType: "image/webp")
        },
        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .Success(let upload, _, _):
                print("Success!")
            case .Failure(let encodingError):
                print("Failure!")
            }
        }
    )
    

    where data is an UIImage which was encoded using YYImageEncoder like that:

    let webpEncoder = YYImageEncoder(type: .WebP)
    webpEncoder?.quality = 0.8
    webpEncoder?.addImage(image, duration: 0)
    let data = webpEncoder?.encode()
    

    The server should save the uploaded image and it worked until now but if I use the YYImageEncoder to get the webp representation, it fails with 502 and the error is the following:

    [Result]: FAILURE: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}

    Like I said before, it works well with UIImageJPEGRepresentation(image, 0.8) but not with YYImageEncoder. What exactly does the encode() method return? Is it possible to do an Multipart upload with the YYImageEncoder data?

    opened by koraykoska 2
  • Duplicate webp symbols

    Duplicate webp symbols

    This Issue is more of an observation than a bug:

    Our production project (closed source) has issues linking with WebP when pulled via YYImage. We pull in YYImage+WebP in a subspec of our open source project: https://github.com/imojiengineering/imoji-ios-sdk/blob/master/ImojiSDK.podspec#L18

    I've been able to get this resolved by forking YYImage and recompiling WebP w/o libwebpdecoder here: https://github.com/imojiengineering/YYImage/commit/b79dd0297c1925940d7470f2147dae909e73e9e6

    Note that this only happens for our production project and not any other project. Therefore I'm not sure if there's a project setting we've got misconfigured.

    At any rate, the error we were getting suggests that there are duplicate symbols in the WebP build. I'm curious as to why it doesn't fail for other projects.

    Message

    duplicate symbol _WebPMultRows in:
        /Users/nkhoshini/projects/imoji-ios/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpdsp_la-alpha_processing.o)
        /Users/nkhoshini/projects/imoji-ios/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpdspdecode_la-alpha_processing.o)
    duplicate symbol _WebPMultARGBRows in:
        /Users/nkhoshini/projects/imoji-ios/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpdsp_la-alpha_processing.o)
        /Users/nkhoshini/projects/imoji-ios/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpdspdecode_la-alpha_processing.o)
    duplicate symbol _WebPInitAlphaProcessing in:
        /Users/nkhoshini/projects/imoji-ios/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpdsp_la-alpha_processing.o)
        /Users/nkhoshini/projects/imoji-ios/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpdspdecode_la-alpha_processing.o)
    duplicate symbol _WebPMultRowC in:
        /Users/nkhoshini/projects/imoji-ios/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpdsp_la-alpha_processing.o)
        /Users/nkhoshini/projects/imoji-ios/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpdspdecode_la-alpha_processing.o)
    
    

    Symbol dump of YYImage/Vendor/WebP.framework/WebP

    ~$ nm WebP | grep  _WebPMultRows
                     U _WebPMultRows
    0000000000000270 T _WebPMultRows
    0000000000000270 T _WebPMultRows
                     U _WebPMultRows
    

    Configuration Xcode 7.3 iOS SDK 9.3 OSX 10.11

    opened by nkhoshini 2
  • Possible memory leaks

    Possible memory leaks

    Hello, thanks for making this library!

    I'm just referring to FBInfer's report, appreciate it if they can be fixed!

    Cheers. --------------------------------Report begins----------------------------------------------- Pods/YYImage/YYImage/YYImageCoder.m:663: error: MEMORY_LEAK memory dynamically allocated by call to YYCGColorSpaceGetDeviceRGB() at line 663, column 36 is not reachable after line 663, column 5 1.
    2. BOOL YYCGColorSpaceIsDeviceRGB(CGColorSpaceRef space) { 3. > return space && CFEqual(space, YYCGColorSpaceGetDeviceRGB()); 4. } 5.

    Pods/YYImage/YYImage/YYImageCoder.m:667: error: MEMORY_LEAK memory dynamically allocated by call to YYCGColorSpaceGetDeviceGray() at line 667, column 36 is not reachable after line 667, column 5 1.
    2. BOOL YYCGColorSpaceIsDeviceGray(CGColorSpaceRef space) { 3. > return space && CFEqual(space, YYCGColorSpaceGetDeviceGray()); 4. } 5.

    Pods/YYImage/YYImage/YYImageCoder.m:887: error: MEMORY_LEAK memory dynamically allocated by call to YYCGColorSpaceGetDeviceRGB() at line 887, column 81 is not reachable after line 887, column 32

    1.       CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Host;
      
    2.       bitmapInfo |= hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst;
      
    3.     CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, 0, YYCGColorSpaceGetDeviceRGB(), bitmapInfo);
      
    4.       if (!context) return NULL;
      
    5.       CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); // decode
      

    Pods/YYImage/YYImage/YYImageCoder.m:2055: error: MEMORY_LEAK memory dynamically allocated by call to YYCGColorSpaceGetDeviceRGB() at line 2055, column 91 is not reachable after line 2055, column 40

    1.               }
      
    2.           } else {
      
    3.             CGContextRef context = CGBitmapContextCreate(NULL, _width, _height, 8, 0, YYCGColorSpaceGetDeviceRGB(), kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
      
    4.               if (context) {
      
    5.                   CGContextDrawImage(context, CGRectMake(0, _height - height, width, height), imageRef);
      

    Pods/YYImage/YYImage/YYImageCoder.m:2197: error: MEMORY_LEAK memory dynamically allocated by call to YYCGColorSpaceGetDeviceRGB() at line 2197, column 75 is not reachable after line 2197, column 9

    1.   if (!_blendCanvas) {
      
    2.       _blendFrameIndex = NSNotFound;
      
    3.     _blendCanvas = CGBitmapContextCreate(NULL, _width, _height, 8, 0, YYCGColorSpaceGetDeviceRGB(), kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
      
    4.   }
      
    5.   BOOL suc = _blendCanvas != NULL;
      

    Pods/YYImage/YYImage/YYImageCoder.m:2416: error: MEMORY_LEAK memory dynamically allocated to gifProperty by call to alloc() at line 2414, column 37 is not reachable after line 2416, column 9

    1.       NSDictionary *gifProperty = @{(__bridge id)kCGImagePropertyGIFDictionary:
      
    2.                                       @{(__bridge id)kCGImagePropertyGIFLoopCount: @(_loopCount)}};
      
    3.     CGImageDestinationSetProperties(destination, (__bridge CFDictionaryRef)gifProperty);
      
    4.   }
      
    opened by ngheungyu 2
  • Memory Leak in 1.0

    Memory Leak in 1.0

    I am using 1.0 to animate a sequence of PNGs (380 in total @ 60 fps) and have run into serious memory leak issues with that cause the app to crash after a while.

    Xcode console first prints this continuously: <Error>: CGBitmapContextInfoCreate: unable to allocate 3469440 bytes for bitmap data

    After a while the more lines appear (again printed continuously): <Error>: CGBitmapContextInfoCreate: unable to allocate 3469440 bytes for bitmap data malloc: *** mach_vm_map(size=8388608) failed (error code=3) *** error: can't allocate region securely *** set a breakpoint in malloc_error_break to debug

    After a few more seconds of animating the app crashes.

    I tried to find the responsible part with Instruments ("Leaks") and found the following leak causing the majority of the memory usage (there are hundreds of UIImages retained):

    Collapsed: bildschirmfoto 2016-03-09 um 13 51 19

    Expanded: bildschirmfoto 2016-03-09 um 13 51 26

    Filtered ("unpaired" only): bildschirmfoto 2016-03-09 um 14 04 35

    I tried setting maxBufferSize to a reasonable value, but that didn't help. Any ideas on what might cause the severe leaks?

    opened by philiplaskowski 2
  • retain cycle

    retain cycle

    I have find some CF class not release and cause some retain cycle,Please review code,Thank You,My great Leader for example,YYImageCoder ---- updateSourceImageIO

    opened by kevintianyao 0
  • Problems using lib in simulator

    Problems using lib in simulator

    The library is presenting the following issue when build for iOS simulator:

    In <...>/Pods/YYImage/Vendor/WebP.framework/WebP(libwebpencode_la-config.o), building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

    Any help?

    opened by rafagan 4
  • Subclassing YYImage

    Subclassing YYImage

    Hello all, hope there's still someone reading this. In a number of issues the answerer suggests to solve problem by subclassing YYImage, eg. #1 , #36 , #146 .

    Say that MyImage is the subclass name. The point is that, as soon as one tries to invoke MyImage(named: "whatever"), you get into typical errors of missing initializers in subclass.

    Q1: Why does every suggestion completely misses to mention that? Maybe there's something wrong we're doing and I'm missing something evident.

    Q2: We'd like to avoid duplicating code from YYImage class factory methods like:

    + (YYImage *)imageNamed:(NSString *)name
    

    or from initializers:

    - (instancetype)initWithData:(NSData *)data scale:(CGFloat)scale
    

    but then there seems to be no way to invoke those from the subclass initializer, at least not from Swift.

    opened by GiuseppePiscopo 0
Releases(1.0.3)
  • 1.0.3(Jul 13, 2016)

    • Fix memory issue when play YYSpriteSheetImage with unreleased CG raster data.
    • Fix empty return value from YYCGImageCreateWithWebPData when decode webp frame with nonzero canvas offset. #41
    • Fix nil return value when encode animated GIF from data source. #44
    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(May 20, 2016)

  • 1.0.1(Apr 21, 2016)

  • 1.0(Apr 21, 2016)

Owner
null
Async GIF image decoder and Image viewer supporting play GIF images. It just use very less memory.

YLGIFImage Asynchronized GIF image class and Image viewer supporting play/stop GIF images. It just use very less memory. Following GIF usually will co

Yong Li 1.8k Aug 15, 2022
High performance and delightful way to play with APNG format in iOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built with high-level abstractions and brings a

Wei Wang 2.1k Jan 2, 2023
Complete Animated GIF Support for iOS, with Functions, NSJSONSerialization-style Class, and (Optional) UIImage Swizzling

AnimatedGIFImageSerialization This library is no longer maintained. In iOS 13+ and macOS 10.15+, use CGAnimateImageAtURLWithBlock instead. AnimatedGIF

Mattt 1.1k Sep 29, 2022
Performant animated GIF engine for iOS

FLAnimatedImage is a performant animated GIF engine for iOS: Plays multiple GIFs simultaneously with a playback speed comparable to desktop browsers H

Flipboard 7.8k Dec 29, 2022
High-performance animated GIF support for iOS in Swift

Gifu adds protocol-based, performance-aware animated GIF support to UIKit. (It's also a prefecture in Japan). Install Swift Package Manager Add the fo

Reda Lemeden 2.8k Jan 4, 2023
XAnimatedImage is a performant animated GIF engine for iOS written in Swift based on FLAnimatedImage

XAnimatedImage is a performant animated GIF engine for iOS written in Swift based on FLAnimatedImage. An illustration is shown below: Features Plays m

Khaled Taha 561 Sep 9, 2022
🌠 A small UIImage extension with gif support

?? A small UIImage extension with gif support

SwiftGif 1.3k Dec 20, 2022
SwiftyGif - High performance & easy to use Gif engine

SwiftyGif High performance & easy to use Gif engine Features UIImage and UIImageView extension based Remote GIFs with customizable loader Great CPU/Me

Alexis Creuzot 1.7k Jan 3, 2023
Convert live photos and videos into animated GIFs in iOS, or extract frames from them.

Create a GIF from the provided video file url, Or extract images from videos. This repository has been separated from original repo along with some no

gitmerge 83 May 18, 2022
Test2 - A curated list of Open Source example iOS apps developed in Swift

Example iOS Apps A curated list of Open Source example iOS apps developed in Swi

null 0 Jan 4, 2022
Captcha implementation in ios App

CaptchaDemo_ios A Swift project to showcase implementation of Google ReCaptcha in iOS Application. Features A light weight basic wrapper to handle com

Tanvi jain 1 Feb 7, 2022
iOS implementation of the Catrobat language

Catty Catty, also known as Pocket Code for iOS, is an on-device visual programming system for iPhones. Catrobat is a visual programming language and s

null 74 Dec 25, 2022
Encode and decode deeply-nested data into flat Swift objects

DeepCodable: Encode and decode deeply-nested data into flat Swift objects Have you ever gotten a response from an API that looked like this and wanted

Mike Lewis 91 Dec 26, 2022
An animated gif & apng engine for iOS in Swift. Have a great performance on memory and cpu usage.

Features Small but complete, only200lines of code. Allow to control display quality, memory usage, loop time and display progress. Have a great perfor

Jiawei Wang 1k Nov 9, 2022
Async GIF image decoder and Image viewer supporting play GIF images. It just use very less memory.

YLGIFImage Asynchronized GIF image class and Image viewer supporting play/stop GIF images. It just use very less memory. Following GIF usually will co

Yong Li 1.8k Aug 15, 2022
APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built on top of a modified version of libpng wit

Wei Wang 2.1k Dec 30, 2022
High performance and delightful way to play with APNG format in iOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built with high-level abstractions and brings a

Wei Wang 2.1k Jan 2, 2023
Media view which subclasses UIImageView, and can display & load images, videos, GIFs, and audio and from the web, and has functionality to minimize from fullscreen, as well as show GIF previews for videos.

I've built out the Swift version of this library! Screenshots Description ABMediaView can display images, videos, as well as now GIFs and Audio! It su

Andrew Boryk 80 Dec 20, 2022
Complete Animated GIF Support for iOS, with Functions, NSJSONSerialization-style Class, and (Optional) UIImage Swizzling

AnimatedGIFImageSerialization This library is no longer maintained. In iOS 13+ and macOS 10.15+, use CGAnimateImageAtURLWithBlock instead. AnimatedGIF

Mattt 1.1k Sep 29, 2022
High-performance animated GIF support for iOS in Swift

Gifu adds protocol-based, performance-aware animated GIF support to UIKit. (It's also a prefecture in Japan). Install Swift Package Manager Add the fo

Reda Lemeden 2.6k Jun 21, 2021