简体   繁体   English

如何将相机胶卷中的所有照片和视频插入阵列?

[英]How to insert all photos and videos from camera roll into array?

有没有一种方法可以将相机胶卷中的所有内容添加到阵列中?

import Photos

class MyVC: UIViewController 
{
var images:NSMutableArray! // Array for storing images


func fetchPhotos () {
    images = NSMutableArray()
    self.fetchPhotoAtIndexFromEnd(0)
}


func getImageAtIndex(index:Int) {

    let imgManager = PHImageManager.defaultManager()


    var requestOptions = PHImageRequestOptions()
    requestOptions.synchronous = true // if just return thumbnail not img

    // optionally sort the images by creation date
    var fetchOptions = PHFetchOptions()
    fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)]

    if let fetchResult: PHFetchResult = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: fetchOptions) {


        if fetchResult.count > 0 {
            imgManager.requestImageForAsset(fetchResult.objectAtIndex(fetchResult.count - 1 - index) as PHAsset, targetSize: view.frame.size, contentMode: PHImageContentMode.AspectFill, options: requestOptions, resultHandler: { (image, _) in

                // Add img to images array
                self.images.addObject(image)


                if index + 1 < fetchResult.count {
                    self.fetchPhotoAtIndexFromEnd(index + 1)
                } else {

                    println("Completed array: \(self.images)")
                }
            })
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从照片库中检索数组中的所有照片和视频? - How to retrieve all the photos and videos in an array from Photos library? 如何在文档中显示所有视频以及相机相册中的照片? - How to display all the videos along with photos from camera album in documents? 如何从相机胶卷中获取照片? - How to get photos from camera roll? 如何将 PHAsset 的参考从“所有照片”/“相机胶卷”移动到特定的 PHAssetCollection? - How to move reference of PHAsset from “All Photos”/“Camera Roll” to Specific PHAssetCollection? 如何迭代存储在相机胶卷中的所有视频? - How to iterate over all videos stored in camera roll? 将相机胶卷中的所有图像存储为数组 - storing all images from camera roll as an array 将相机卷照片存储到数组中以使用Swift 3显示 - Store Camera Roll photos into array to display with Swift 3 如何在Swift中将视频从“ file:///”保存到相机胶卷中? - How to save videos from “file:///” to camera roll in Swift? 如何对iOS相机胶卷中的视频采取特定的时间间隔? - How to take specific time interval on videos from Camera Roll on iOS? 如何自动将相机胶卷中的所有照片上传到亚马逊S3存储桶中,例如相机同步或保管箱 - How to auto upload the camera roll all photos to amazon s3 bucket like camera sync or dropbox doing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM