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 并列第二。

  • 相关阅读:
    数据结构串的运算算法
    java文件读取
    我的博客园
    示例 Edit 关闭键盘再显示
    用 Inkscape 做 SVG 给 TPath
    FMX 讯息框 FrameDialog
    让 ListView 在 Android 可回弹
    修正 ColorPanel 选色缓慢问题
    Eclipse Tomcat Project报错:HTTP Status 404错误
    gradle web项目启动报错: java.lang.ClassNotFoundException: org.springframework.web.util.IntrospectorCleanupListener
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10444180.html
Copyright © 2011-2022 走看看