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

  • 相关阅读:
    Dubbo源码分析系列---服务的发布
    Dubbo源码分析系列---扩展点加载
    Jdk动态代理和CGLIB动态代理大比拼
    定时任务的一些思路
    技术人的职业发展
    2017面试碎碎念
    Tiny Mapper
    RabbitMQ 简介
    Load Test Analyzer Overview
    2015 如期而至,你好
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10444180.html
Copyright © 2011-2022 走看看