1
我使用資產庫從URL獲取圖像,我的代碼是在iOS的資源庫的問題 - 5
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *largeimage;
if (iref) {
largeimage = [UIImage imageWithCGImage:iref];
}
[self customeButtonCreated:self];
NSData* thumbImageData = [[NSData alloc] initWithContentsOfFile:imagePath];
btn1.frame = CGRectMake(x, y, WIDTH, HEIGHT);
[btn1 setTag:tag];
//[media_id addObject:[allKey objectAtIndex:0]];
[btnURl addObject:imagePath];
UIImage *tempImage = [[UIImage alloc]initWithData:thumbImageData];
[btn1 setImage:largeimage forState:UIControlStateNormal];
btn1.imageView.contentMode = UIViewContentModeScaleAspectFit;
[tempImage release];
[newView addSubview:btn1];
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[thumbImageData release];
imgcount++;
NSLog(@"Iamge count ---%d",imgcount);
tag++;
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
NSLog(@"Cannot get image - %@",[myerror localizedDescription]);
};
if ([seprateArr count] == 2) {
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"assets-library://asset/asset.JPG?id=%@&ext=%@",[seprateArr objectAtIndex:0],[seprateArr objectAtIndex:1]]];
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:url resultBlock:resultblock failureBlock:failureblock];
}
它是在IOS做工精細 - 4或以下,但在IOS - 5它不進入在塊顯示errir
無法獲取圖像 - 環球拒絕訪問
這方面的任何解決方案?
這裏是什麼photoName對我的作品?圖像的名稱? – PJR
意味着我必須使用[UIImage imageNamed:photoName]; – PJR
photoName是圖片的標題和photoUrl的資源網址。你可以像這樣訪問UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:photoUrl]]]; –