相片的應用真的非常之廣,使用WSAssetPicker來多選相片,除了要注意記憶體不能爆掉之外,存取速度也是我們所在意的因素,Asset所提供的特性可以讓我們輕易取得四種不同的影像解析度,就看用途為何來決定。
這裡展示四種影像解析度的取得:fullResolutionImage、fullScreenImage、thumbnail、aspectRatioThumbnail。
UIImage *image = [[UIImage alloc] initWithCGImage:asset.defaultRepresentation.fullResolutionImage]; image = [[UIImage alloc] initWithCGImage:asset.defaultRepresentation.fullScreenImage]; image = [[UIImage alloc] initWithCGImage:asset.thumbnail]; image = [[UIImage alloc] initWithCGImage:asset.aspectRatioThumbnail];
在debug環境下印出以上四種影像的大小:
(lldb) p image.size
(CGSize) $0 = (width=3264, height=2448)
(lldb) p image.size
(CGSize) $1 = (width=960, height=720)
(lldb) p image.size
(CGSize) $2 = (width=157, height=157)
(lldb) p image.size
(CGSize) $3 = (width=340, height=256)
原本使用fullScreenImage來進行後續處理,然而因為載到記憶體中,又存入硬碟中,所需的時間還是相當久,後來發現可用aspectRatioThumbnail取代之,因為檔案容量小約八倍,於是存取速度就快約八倍,讓使用者體驗變得更好,而且在顯示在螢幕上的大小和影像解析度只有些微差距。
發表留言