📅  最后修改于: 2022-03-11 15:00:00.484000             🧑  作者: Mango
func generateThumbnailRepresentations() {
// Set up the parameters of the request.
guard let url = Bundle.main.url(forResource: "example", withExtension: "png") else {
// Handle the error case.
assert(false, "The URL can't be nil")
return
}
let size: CGSize = CGSize(width: 60, height: 90)
let scale = UIScreen.main.scale
// Create the thumbnail request.
let request = QLThumbnailGenerator.Request(fileAt: url,
size: size,
scale: scale,
representationTypes: .all)
// Retrieve the singleton instance of the thumbnail generator and generate the thumbnails.
let generator = QLThumbnailGenerator.shared
generator.generateRepresentations(for: request) { (thumbnail, type, error) in
DispatchQueue.main.async {
if thumbnail == nil || error != nil {
// Handle the error case gracefully.
} else {
// Display the thumbnail that you created.
}
}
}
}