6

我想知道如何使用 URL 检索图像。我正在使用 ALAsset。我按照从 iPhone 中的 ALAsset 检索到的 URL 中的以下链接显示图像中的答案(带有勾号的那个) 。如何检索图像并上传?

4

3 回答 3

16

您是否设法获得了 ALAsset?完成后,获取图像很容易。要获取缩略图,资产有一个方法...缩略图。

UIImage *img = [UIImage imageWithCGImage:[myAsset thumbnail]];

要获得完整的 Res 图像,您必须通过默认表示。

UIImage *img = [UIImage imageWithCGImage:[[myAsset defaultRepresentation] fullResolutionImage]

希望这可以帮助

于 2011-04-01T18:57:18.277 回答
3

我知道这是一个老问题,但以防万一其他人来,我找到了另一种方法(需要 iOS 5+),它返回更易于使用的图像:

UIImage *img = [UIImage imageWithCGImage:[[myAsset defaultRepresentation] 
               fullScreenImage];


来自以下文档fullScreenImage

在 iOS 5 及更高版本中,此方法返回完全裁剪、旋转和调整的图像——与用户在照片或图像选择器中看到的完全一样。

Monkybonk05 的答案确实有效,但没有裁剪或旋转。

于 2013-04-11T14:49:23.493 回答
2

看看这个方法

+ (UIImage *)imageFromAsset:(ALAsset *)asset
{
    ALAssetRepresentation *representation = [asset defaultRepresentation];
    return [UIImage imageWithCGImage:representation.fullResolutionImage
                               scale:[representation scale]
                         orientation:(UIImageOrientation)[representation orientation]];
}

我根据这个要点稍微调整了它:https ://gist.github.com/NR4TR/8576048

于 2014-04-04T08:51:02.957 回答