swift에서 옵션을 주고 사진을 가져오는 방법이있나요?

조회수 2318회

사진옵션(사진크기,날짜 등등)을 지정해서 그 옵션에 맞는 사진들을 가지고오는 방법이 있나요?

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • PHAsset를 가지고 오신 다음

    • 날짜 같은 경우 asset.creationDate
    • 장소 같은 경우 asset.location
    • 사진 크기는 asset.pixelWidth, asset.pixelHeight

    정보를 가지고 와서 비교 하신다음 사진들 가지고 오시면 될꺼 같아요 :)

    import Photos
    
    override func viewDidLoad() {
    
        let options = PHFetchOptions()
        options.predicate = NSPredicate(format: "mediaType = %d",PHAssetMediaType.Image.rawValue)
        options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: true) ]
        let result : PHFetchResult = PHAsset.fetchAssetsWithOptions(options)
    
        for i in 0 ..< assetsFetchResults.count {
             let asset = assetsFetchResults[i] as! PHAsset        
    
            print("date = \(asset.creationDate!)")
            print("location = \(asset.location)")
            print("width = \(asset.pixelWidth), height=\(asset.pixelHeight))
        }
    
    }
    
    

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)