【问题标题】:Load an image to UIImage from a file path to the asset library将图像从资源库的文件路径加载到 UIImage
【发布时间】:2011-12-26 11:34:30
【问题描述】:

与我之前的问题here有关。

我在资源库中有一张图片的路径,例如:

assets-library://asset/asset.JPG?id=1000000001&ext=JPG

现在,我如何将图像从该路径加载到 UIImage 对象?

代码如下:

NSString *path = [occasion imagePath];

//temp
NSLog(@"the 2nd occasion imagePath is: %@", path);
//end

if (path != nil)
{
    //UIImage *image = [UIImage imageNamed:path];
    UIImage *image = [UIImage imageWithContentsOfFile:path];

    image = [image imageByScalingAndCroppingForSize:CGSizeMake(36.0, 42.0)];
    [[cell imageView] setImage:image];
}

【问题讨论】:

    标签: objective-c ios uiimage assets filepath


    【解决方案1】:

    您也可以使用[myasset aspectRatioThumbnail] 获取您的图片。

    【讨论】:

      【解决方案2】:

      来自我上面评论中链接的答案:

          -(void)findLargeImage
      {
          NSString *mediaurl = [self.node valueForKey:kVMMediaURL];
      
          //
          ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
          {
              ALAssetRepresentation *rep = [myasset defaultRepresentation];
              CGImageRef iref = [rep fullResolutionImage];
              if (iref) {
                  largeimage = [UIImage imageWithCGImage:iref];
                  [largeimage retain];
              }
          };
      
          //
          ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
          {
              NSLog(@"booya, cant get image - %@",[myerror localizedDescription]);
          };
      
          if(mediaurl && [mediaurl length] && ![[mediaurl pathExtension] isEqualToString:AUDIO_EXTENSION])
          {
              [largeimage release];
              NSURL *asseturl = [NSURL URLWithString:mediaurl];
              ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
              [assetslibrary assetForURL:asseturl 
                             resultBlock:resultblock
                            failureBlock:failureblock];
          }
      }
      

      【讨论】:

        【解决方案3】:

        尝试以下方法: (UIImage *)imageWithContentsOfFile:(NSString *)path

        【讨论】:

          猜你喜欢
          • 2016-10-23
          • 1970-01-01
          • 1970-01-01
          • 2013-06-16
          • 2013-03-12
          • 1970-01-01
          • 2018-03-29
          • 2011-06-03
          • 1970-01-01
          相关资源
          最近更新 更多