本文介绍了发布到服务器时iOS 4图像导向错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我是一个相对较新的iOS开发人员。我正在尝试构建一个将图像上传到服务器的应用程序。但是,当我使用元数据获取图像时,方向始终关闭。这里是我使用的代码: - (无效)getJPEGFromAssetForURL:(NSURL *)网址{ ALAssetsLibrary * assetslibrary = [[ALAssetsLibrary alloc] init]; [assetslibrary assetForURL:url resultBlock:^(ALAsset * myasset){ self.rep = [myasset defaultRepresentation]; NSLog(@getJPEGFromAssetForURL:%@的默认资产表示:uti:%@ size:%lld url:%@ orientation:%d scale:%f metadata:%@, url,[rep UTI],[rep size],[rep url],[rep orientation], [rep scale],[rep metadata]); 字节* buf = malloc([rep size]); //当关联的NSData被释放时,将自动释放 NSError * err = nil; NSUInteger bytes = [rep getBytes:buf fromOffset:0LL length:[rep size] error:& err]; if(err || bytes == 0){ // err和bytes == 0冗余? Doc说0返回意味着 //错误发生,这可能意味着返回NSError。 NSLog(@来自getBytes:%@的错误,错误); self.imageJPEG = nil; 返回; } self.imageJPEG = [NSData dataWithBytesNoCopy:buf length:[rep size] freeWhenDone:YES]; // YES表示免费的malloc'ed buf在取消分配时支持这个} failureBlock:^(NSError * err){ NSLog(@无法获取资产%@:%@ ,url,err); }]; [assetslibrary release]; } 当我继续将imageJPEG变量中包含的图像数据发布到我的网络服务器,它遇到所有元数据完整,但图像方向不正确。 我也尝试了以下相同的结果: UIImage * largeimage = [UIImage imageWithCGImage:iref scale:1.0 orientation:[rep orientation]]; NSData * webData = UIImageJPEGRepresentation(largeimage,0.5); 这里是否有我遗漏的东西,或者这是图像存储方式的错误。如果你能以任何方式提供帮助,请告诉我。我很高兴能把这个应用程序拿出来。 非常感谢。 解决方案 的iOS的UIImagePickerController上传后的结果图片方向 - 这篇文章回答了我的问题! I am a relatively new iOS developer. I am attempting to build an app that uploads images to a server. However, when I get the image with metadata, the orientation is always off. Here is the code I am using:- (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];}When I go ahead and post the image data contained in the imageJPEG variable to my webserver, it comes across with all the metadata intact, but the image is oriented incorrectly.I also tried the following with the same result:UIImage *largeimage = [UIImage imageWithCGImage:iref scale:1.0 orientation:[rep orientation]];NSData *webData = UIImageJPEGRepresentation(largeimage,0.5);Is there something I'm missing here or this is a bug in the way the images are stored. Please let me know if you can help in any way, I am really excited to get this app out.Thanks so much. 解决方案 iOS UIImagePickerController result image orientation after upload - This post answered my question! 这篇关于发布到服务器时iOS 4图像导向错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-13 23:20