For those of you who have been struggling with image display performance, macOS ‘fastest image parsing library is now open source.

SwiftFastImageSize

Quickly get the image type and size

The image type and size can be determined by protocol by loading only the image file header, which is used for the display of local images (later added to the remote) list. It is especially suitable for the view that needs dynamic layout according to the image size, such as CollectionView and other waterfall flow layout/adaptive layout.

Technical advantages

  1. You don’t need to load the entire file
  2. Supports BMP/JPG/PNG/apng/GIF/webp

The sample code

The full sample code is in Tests

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

Best practices

  1. SwiftFastImageSize to get the size of all images for layout calculation;
  2. Used for the current image to displayImageIOIn the libraryCGImageSourceGet the picture information again, and the content of each frame for display.

The code window

  1. No hierarchical design, compact code
  2. useBinUtilsByte unpack, simple code

agreement

  • Follow MIT protocol
  • Feel free to enjoy and participate in open source

Thanks for github.com/scardine/im… And github.com/nst/BinUtil…