Coder Social home page Coder Social logo

swiftfastimagesize's Introduction

SwiftFastImageSize

Github地址

快速获得图片类型及尺寸大小

只加载图片文件头就可以通过协议确定图片类型及尺寸,用于本地图片(后续加入远程)列表展示,特别适合需要根据图片尺寸动态布局的视图,如CollectionView等瀑布流布局/自适应布局。

技术优势

  1. 无需加载整个文件
  2. 支持bmp/jpg/png/apng/gif/webp

示例代码

完整示例代码在Tests

let sizer = SwiftFastImageSize(path)
do {
    try sizer.parse()
    XCTAssertEqual(sizer.imageType, type)
    XCTAssertEqual(sizer.imageSize, size)
} catch let error {
    print("error", error)
}

最佳实践

  1. 通过SwiftFastImageSize获得全部图片的图片尺寸,用于布局计算;
  2. 针对当前要显示的图片使用ImageIO库中的CGImageSource再次获取图片信息,及每一帧内容用于显示。

代码亮点

  1. 没有分层设计,代码紧凑
  2. 使用BinUtils进行字节解包,代码简洁

协议

  • 遵循 MIT 协议
  • 请自由地享受和参与开源

Thanks for https://github.com/scardine/image_size and https://github.com/nst/BinUtils

swiftfastimagesize's People

Contributors

wulie88 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.