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
- You don’t need to load the entire file
- 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
- SwiftFastImageSize to get the size of all images for layout calculation;
- Used for the current image to display
ImageIO
In the libraryCGImageSource
Get the picture information again, and the content of each frame for display.
The code window
- No hierarchical design, compact code
- use
BinUtils
Byte 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…