zoukankan      html  css  js  c++  java
  • ios的图片解压

    YYKit SDWebImage FLAnimatedImage YYKit YYCGImageCreateDecodedCopy YYImageCoder

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    CGImageRef YYCGImageCreateDecodedCopy(CGImageRef imageRef, BOOL decodeForDisplay) {

        ...

        if (decodeForDisplay) { // decode with redraw (may lose some precision)

            CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef) & kCGBitmapAlphaInfoMask;

            BOOL hasAlpha = NO;

            if (alphaInfo == kCGImageAlphaPremultipliedLast ||

                alphaInfo == kCGImageAlphaPremultipliedFirst ||

                alphaInfo == kCGImageAlphaLast ||

                alphaInfo == kCGImageAlphaFirst) {

                hasAlpha = YES;

            }

            // BGRA8888 (premultiplied) or BGRX8888

            // same as UIGraphicsBeginImageContext() and -[UIView drawRect:]

            CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Host;

            bitmapInfo |= hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst;

            CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, 0, YYCGColorSpaceGetDeviceRGB(), bitmapInfo);

            if (!context) return NULL;

            CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); // decode

            CGImageRef newImage = CGBitmapContextCreateImage(context);

            CFRelease(context);

            return newImage;

        } else {

            ...

        }

    }

    imageRef newImage 使用 CGBitmapContextCreate 函数创建一个位图上下文;

    • 使用 CGContextDrawImage 函数将原始位图绘制到上下文中;
    • 使用 CGBitmapContextCreateImage 函数创建一张新的解压缩后的位图。

    你可以用PINRemoteImage或者YYWebImage来实现这个效果

    这次 YYKit 终于翻盘了,解压缩 JPEG 图片的性能最好,SDWebImage 和 FLAnimatedImage 并列第二。

  • 相关阅读:
    HDu 2830 Matrix Swapping II(dp)
    服务器http处理流程
    iOS网络缓存机制
    软件设计需要的两项能力:理解与抽象
    编程思想的本质
    编程思想:面向对象与面向过程
    You Can Customize Synthesized Instance Variable Names @property
    nil / Nil / NULL / NSNull VS objc_msgSend
    对OC中property的一点理解
    @property 的本质是什么?
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10444180.html
Copyright © 2011-2022 走看看