我已经设法使用以下代码获取存储在资产库中的照片的原始文件名:
NSURL *url = [[NSURL alloc] initWithString:project.photo];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library assetForURL:url resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
_filename = [rep filename];
NSLog(@"filename for image is: %@", _filename);
if (_filename != nil)
{
UIImage *image = [UIImage imageWithContentsOfFile:_filename];
NSLog(@"image is! %f", image.size.height);
[image drawInRect:CGRectMake( (pageSize.width - image.size.width/2)/2, 350, image.size.width/2, image.size.height/2)];
}
NSString 变量 _filepath 将图像的原始文件路径存储为:
IMG_0294.JPG
我想做的就是从照片库中获取这张图片,并使用以下代码将其绘制在 pdf 文档中:
[image drawInRect:CGRectMake( (pageSize.width - image.size.width/2)/2, 350, image.size.width/2, image.size.height/2)];
这个绘制代码肯定是有效的,因为我已经使用存储在应用程序目录中的图像进行了尝试。我只需要找到一种使用文件路径来创建 UIImage 或将其指向该照片的完整目录的方法。
输出到控制台时,图像变量返回 null。
任何帮助都会很棒。