2015년 3월 1일 일요일

앨범에서 마지막 찍은 사진 가져오기

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];



    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.


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



        // Within the group enumeration block, filter to enumerate just photos.


        [group setAssetsFilter:[ALAssetsFilter allPhotos]];



        // Chooses the photo at the last index


        [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets] - 1)]options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {



            // The end of the enumeration is signaled by asset == nil.


            if (alAsset) {


                ALAssetRepresentation *representation = [alAsset defaultRepresentation];


                UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];


                [latestPhoto resizeImageToWidth:50];



                if (latestPhoto){


                    [self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateNormal];


                    [self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateHighlighted];


                }


            }


        }];


    } failureBlock: ^(NSError *error) {


    }];

0 comments:

댓글 쓰기