次のコードを使用して、アセットライブラリに保存されている写真の元のファイル名を取得できました。
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として返されます。
どんな助けでも素晴らしいでしょう。