ELCImagePicker를 사용하면서 asselts를 사용하여 사진 라이브러리에서 한 번에 여러 장의 사진을 가져 오는 동안 동일한 문제가 발생했습니다. 가져 오는 데 걸리는 시간을 줄일 수는 없지만 충돌 문제는 해결됩니다.
for (int j=0; j<[assetArray count]; j++)
{
@autoreleasepool // This is compiler level feature so will only work on xcode 4.1 or above
{
ALAsset *assest = [assetArray objectAtIndex:j];
CGImageRef imageRef = assest.defaultRepresentation.fullResolutionImage;
UIImage *image = [UIImage imageWithCGImage:imageRef];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:documentsPath atomically:YES];
}
}
가능한 시도가 assetArray 대신 전체 ALAsset 객체 만 AssetURL를 저장하고 URL에서 한 번에 ALAsset을 만들 경우 때문에 메모리 사용량을 줄이는 데 도움이 될 수있다. 이러한 경우에 당신은
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [[myasset defaultRepresentation] fullResolutionImage];
if (iref) //You have image so use it
{
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can't get image - %@",[myerror localizedDescription]);
};
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:imageURL resultBlock:resultblock failureBlock:failureblock];
내가이 같은 문제가 없었다하지만 난 데이터베이스에 자산 URL을 저장하여 그것을 해결하고 난 문서 디렉토리에 이미지를 저장해야 할 때 난으로 자산 하나를 얻을 하나는 문서 디렉토리에 이미지를 저장합니다. 한 가지 이유는 배열에 자산을 저장하고 자산 URL을 저장하는 것이고 메모리 문제를 줄이는 자동 릴리스 풀의 루프에 대해 하나 더 실행하는 것입니다. – Leena