我想從相機膠捲獲取所有圖像並從它們中創建一個UIImage陣列。從相機膠捲創建一個UIImages陣列
我一直在試圖弄清楚如何做到這一點大約一天,我已經無處可去。我似乎無法弄清楚如何從相機膠捲中檢索只有項目。看來,我所見過的所有樣本都列舉了所有的相冊。雖然我可能是錯的。
任何幫助,將不勝感激。謝謝!
我想從相機膠捲獲取所有圖像並從它們中創建一個UIImage陣列。從相機膠捲創建一個UIImages陣列
我一直在試圖弄清楚如何做到這一點大約一天,我已經無處可去。我似乎無法弄清楚如何從相機膠捲中檢索只有項目。看來,我所見過的所有樣本都列舉了所有的相冊。雖然我可能是錯的。
任何幫助,將不勝感激。謝謝!
您是否試過ALAssetsLibrary?像這樣:
assets = [[NSMutableArray array] init]; // Prepare array to have retrieved images by Assets Library.
void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *asset, NSUInteger index, BOOL *stop) {
if(asset != NULL) {
[assets addObject:asset];
dispatch_async(dispatch_get_main_queue(), ^{
[self insertArray];
});
}
};
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
// Create instance of the Assets Library.
library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos // Retrieve the images saved in the Camera roll.
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(@"Failed.");
}];
將會抓住他們。那麼這樣做是爲了使它們(這是邪惡的哈克。你要根據需要導入他們,而不是一下子這個樣子,或者你會碰到內存問題和崩潰)
-(void) insertArray {
int i = assetCount++;
if (i>20) {
return;
}
ALAssetRepresentation *rep = [[assets objectAtIndex:i] defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
CGSize cSize = CGSizeMake(75,75);
UIImage *largeimage = [UIImage imageWithCGImage:iref];
UIImage *resizedimage = (UIImage *)[largeimage resizedImage:cSize interpolationQuality:kCGInterpolationHigh];
UIImageView *newView = [[UIImageView alloc] initWithImage:resizedimage];
if((i>0)&&(i%4 == 0)){
rowCount++;
}
colCount = i%4;
newView.frame = CGRectMake(4+(colCount*(75+4)), 4+(rowCount*(75+4)), 75, 75);
[sv addSubview:newView];
[sv setContentSize:CGSizeMake(320, 85+(rowCount*(75+4)))];
NSLog(@"sv frame size is %@ and i is %i", NSStringFromCGRect(sv.frame), i);
}
oops ...我忘記了我在這裏使用了UIImage + Resize庫:[http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/] (http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/) – mrBallistic 2012-02-07 22:23:01
嗨 void(^ assetEnumerator)(ALAsset *,NSUInteger,BOOL *) = ^(ALAsset * asset,NSUInteger index,BOOL * stop) 它未進入此循環 – Nithinbemitk 2013-09-03 03:41:40
你的意思是採摘陣列使用UIImagePickerController的圖像? – Ilanchezhian 2011-12-29 05:09:48
我正在做一些類似於iOS的照片應用程序,但我無法弄清楚如何獲取個人相冊數據。 – bendu 2011-12-29 05:18:17