1

私は比較的新しい iOS 開発者です。画像をサーバーにアップロードするアプリを構築しようとしています。ただし、メタデータを含む画像を取得すると、向きが常にオフになります。私が使用しているコードは次のとおりです。

- (void)getJPEGFromAssetForURL:(NSURL *)url {
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
               resultBlock: ^(ALAsset *myasset) {
                   self.rep = [myasset defaultRepresentation];

                   NSLog(@"getJPEGFromAssetForURL: default asset representation for %@: uti: %@ size: %lld url: %@ orientation: %d scale: %f metadata: %@", 
                         url, [rep UTI], [rep size], [rep url], [rep orientation], 
                         [rep scale], [rep metadata]);


                   Byte *buf = malloc([rep size]);  // will be freed automatically when associated NSData is deallocated
                   NSError *err = nil;
                   NSUInteger bytes = [rep getBytes:buf fromOffset:0LL 
                                             length:[rep size] error:&err];
                   if (err || bytes == 0) {
                       // Are err and bytes == 0 redundant? Doc says 0 return means 
                       // error occurred which presumably means NSError is returned.

                       NSLog(@"error from getBytes: %@", err);
                       self.imageJPEG = nil;
                       return;
                   } 
                   self.imageJPEG = [NSData dataWithBytesNoCopy:buf length:[rep size] 
                                                   freeWhenDone:YES];  // YES means free malloc'ed buf that backs this when deallocated
               }
              failureBlock: ^(NSError *err) {
                  NSLog(@"can't get asset %@: %@", url, err);
              }];
[assetslibrary release];
}

imageJPEG 変数に含まれる画像データを Web サーバーに投稿すると、すべてのメタデータはそのままですが、画像の向きが正しくありません。

私も同じ結果で次のことを試しました:

UIImage *largeimage = [UIImage imageWithCGImage:iref scale:1.0 orientation:[rep orientation]];
NSData *webData = UIImageJPEGRepresentation(largeimage,0.5);

ここに欠けているものはありますか、これは画像の保存方法のバグです。このアプリをリリースできることをとても楽しみにしています。

本当にありがとう。

4

0 に答える 0