亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在iPhone中顯示從ALAsset檢索到的URL圖像

在iPhone中顯示從ALAsset檢索到的URL圖像

呼啦一陣風 2019-07-08 17:32:32
在iPhone中顯示從ALAsset檢索到的URL圖像我使用ALAssetFramework訪問設備照片庫中的文件。到目前為止,我能夠訪問縮略圖并顯示它。我想在圖像視圖中顯示實際的圖像,但是我想不出如何做到這一點。我嘗試在ALAsset對象中使用URL字段,但沒有成功。有人知道怎么做嗎?下面是一些我能夠訪問縮略圖并將其放在表格單元格中的代碼:- (UITableViewCell *)tableView:(UITableView *)tableView           cellForRowAtIndexPath:(NSIndexPath *)indexPath {   static NSString *CellIdentifier = @"Cell";   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];   if (cell == nil) {     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];   }   //here 'asset' represents the ALAsset object   asset = [assets objectAtIndex:indexPath.row];        //i am accessing the thumbnail here   [cell.imageView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];   [cell.textLabel setText:[NSString stringWithFormat:@"Photo %d", indexPath.row+1]];   return cell;}
查看完整描述

3 回答

?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

對于某些人來說,一件有用的事情是同時包含圖像定向和縮放元數據。您可以在結果塊中這樣做,如下所示:

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
    ALAssetRepresentation *rep = [myasset defaultRepresentation];
    CGImageRef iref = [rep fullResolutionImage];
    if (iref) 
    {
        UIImage *largeimage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:[rep orientation]];
        [delegate hiresImageAvailable:large];
    }};

這個imageWIthCGImage在這種情況下呼叫有規模和orientation創建UIImage為了你。

[UIImage imageWithCGImage:iref scale:[rep scale] orientation:[rep orientation]];

需要注意的一個技巧是,如果你使用[rep fullScreenImage]而不是[rep fullResolutionImage]在iOS 5上,你會得到一張已經旋轉的圖像-不過它是iPhone屏幕的分辨率-也就是說,它的分辨率較低。


查看完整回答
反對 回復 2019-07-08
?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

把Warren和OKnox的答案組合成一個簡短的片段:

ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];[assetsLibrary assetForURL:self.selectedPhotos[i] resultBlock: ^(ALAsset *asset){
    ALAssetRepresentation *representation = [asset defaultRepresentation];
    CGImageRef imageRef = [representation fullResolutionImage];
    if (imageRef) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        imageView.image = [UIImage imageWithCGImage:imageRef scale:representation.scale orientation:representation.orientation];
        // ...
    }} failureBlock: ^{
    // Handle failure.}];

我個人喜歡把我的failureBlocknil.


查看完整回答
反對 回復 2019-07-08
  • 3 回答
  • 0 關注
  • 575 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號