简体   繁体   English

将相机胶卷中的所有图像存储为数组

[英]storing all images from camera roll as an array

I am very new to iOS and Objective-C, but I am trying to create an app that contains a component that takes all of the images from the camera roll and creates a slideshow from them. 我是iOS和Objective-C的新手,但是我试图创建一个包含一个组件的应用程序,该组件可以从相机胶卷中获取所有图像并从中创建幻灯片。 I believe the first step is to create an array from all of the images stored in the camera roll. 我相信第一步是根据存储在相机胶卷中的所有图像创建一个数组。 Then I can create an animation from this array. 然后,我可以从该数组创建动画。 Currently, I have a button, designated as "play", that when selected should display this slideshow as a UIImageView. 当前,我有一个名为“播放”的按钮,选择该按钮后应将此幻灯片显示为UIImageView。 However, my code does not work right now. 但是,我的代码目前无法正常工作。 Any help or suggestions would be greatly appreciated. 任何帮助或建议,将不胜感激。 Here is my code so far: 到目前为止,这是我的代码:

- (IBAction)play:(id)sender {
NSMutableArray *allPhotos= [[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

    [group setAssetsFilter:[ALAssetsFilter allPhotos]];
    [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if (result == nil) {
            return;
        }

        ALAssetRepresentation *representation = [result defaultRepresentation];
        UIImage *image = [UIImage imageWithCGImage:[representation fullScreenImage]];
        [allPhotos addObject:image];
    }];

} failureBlock: ^(NSError *error) {

    NSLog(@"No groups");
}];

UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 95, 86, 193)];
animationImageView.animationImages = allPhotos;
animationImageView.animationDuration = 0.5;

[self.view addSubview:animationImageView];
[animationImageView startAnimating];

} }

See my answer here I posted: 在我发布的此处查看我的答案:

Since ALAssetsLibrary is deprecated now and Photo Framework is new one. 由于现在已弃用ALAssetsLibrary,而Photo Framework是新的。 I made my own function in Objective C to get all photos from Camera Roll and store in NSArray and displayed in my Collectionview 我在Objective C中实现了自己的功能,以从“相机胶卷”中获取所有照片并存储在NSArray中并显示在我的Collectionview中

 NSArray *imageArray;
 NSMutableArray *mutableArray;

    -(void)getAllPhotosFromCamera
    {
        imageArray=[[NSArray alloc] init];
        mutableArray =[[NSMutableArray alloc]init];

        PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
        requestOptions.resizeMode   = PHImageRequestOptionsResizeModeExact;
        requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
        requestOptions.synchronous = true;
        PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];

        NSLog(@"%d",(int)result.count);

        PHImageManager *manager = [PHImageManager defaultManager];
        NSMutableArray *images = [NSMutableArray arrayWithCapacity:[result count]];

        // assets contains PHAsset objects.

        __block UIImage *ima;
        for (PHAsset *asset in result) {
            // Do something with the asset

            [manager requestImageForAsset:asset
                               targetSize:PHImageManagerMaximumSize
                              contentMode:PHImageContentModeDefault
                                  options:requestOptions
                            resultHandler:^void(UIImage *image, NSDictionary *info) {
                                ima = image;

                                [images addObject:ima];
                            }];


        }

        imageArray = [images copy];  // You can direct use NSMutuable Array images
    }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM