-1

次の関数を使用してビューから画像を生成しています

-(void)preparePhotos 
{
    [assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
     {
         if(result == nil)
         {
             return;
         }

         NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
         UIImage *img = [[UIImage imageWithCGImage:[[result defaultRepresentation] fullResolutionImage]] resizedImageToSize:CGSizeMake(600, 600)];
         [workingDictionary setObject:img forKey:@"UIImagePickerControllerOriginalImage"];
         [appdelegate.arrImageData addObject:workingDictionary];
     }]; 
}

しかし、この関数が呼び出される回数が増えると、アプリがクラッシュします。この関数または代替関数を最適化して、このような crash.function 呼び出しに至らないデバイス ギャラリーから画像を取得するにはどうすればよいですか。

[self performSelectorInBackground:@selector(preparePhotos) withObject:nil];
4

1 に答える 1

1

フォト ライブラリからすべての画像を取得する場合は、画像自体ではなく、アセットの URL のみを保存する必要があります。photoAssetsインデックスだけを渡すことでこのメソッドを呼び出すことができるよりも、アセットの URL を名前付きの配列に格納しているとしましょう。

- (UIImage *)photoAtIndex:(NSUInteger)index
{
    ALAsset *photoAsset = self.photoAssets[index];

    ALAssetRepresentation *assetRepresentation = [photoAsset defaultRepresentation];

    UIImage *fullScreenImage = [UIImage imageWithCGImage:[assetRepresentation fullScreenImage]
                                                   scale:[assetRepresentation scale]
                                             orientation:UIImageOrientationUp];
    return fullScreenImage;
}

詳細または参照については、 PhotoScrollerおよびMyImagePickerを参照してください。

于 2014-02-04T11:58:51.113 に答える