我在我的應用程序中使用相機功能,並在單擊照片後將圖像保存在文檔目錄中。每當我使用圖像時,這些圖像的方向都會發生變化。因此,對於它,我搜索的計算器和在這個環節得到解決:修復圖像的方向+ iphone
iOS UIImagePickerController result image orientation after upload
但我無法知道如何使用固定方位的方法來獲得圖像的原始方向。如果有人對此有所瞭解,請幫助我。
感謝所有。
我在我的應用程序中使用相機功能,並在單擊照片後將圖像保存在文檔目錄中。每當我使用圖像時,這些圖像的方向都會發生變化。因此,對於它,我搜索的計算器和在這個環節得到解決:修復圖像的方向+ iphone
iOS UIImagePickerController result image orientation after upload
但我無法知道如何使用固定方位的方法來獲得圖像的原始方向。如果有人對此有所瞭解,請幫助我。
感謝所有。
在某處添加該方法。然後:
UIImage *origImage = <from somewhere>;
UIImage *fixed = [origImage fixOrientation];
這是一個類別方法,因此您可以將它添加到任何實現中。通常,良好的做法是創建一個單獨的文件,如UIImage+rotationFix.{m,h}
。
在您的項目
UIImage+fixOrientation
此類別添加,也可以手動創建它通過如下鏈接
[1]:[代碼的UIImage + FixOrientation.h]
https://github.com/j3r3miah/mapmatic-ios/blob/master/Mapmatic/UIImage+FixOrientation.h
[2]:[code for UIImage + FixOrientation.m]
https://github.com/j3r3miah/mapmatic-ios/blob/master/Mapmatic/UIImage+FixOrientation.m
在您的視圖控制器創建這一類文件導入後,
和實現這個的UIImagePickerController委託
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {
UIImage *myimage = [info objectForKey: UIImagePickerControllerOriginalImage];
myimage=myimage.fixOrientation;
}
This fixOrientation method would fix the image orientation in portrait mode.
不在我的項目中工作 – 2015-06-30 08:21:18
+1以獲取清晰的說明。 – 2012-03-27 11:52:25
嗨,謝謝@jennis。涼。 – 2012-03-27 11:56:37
@ScottCorscadden Corscadden我試過了,但它是崩潰並給出錯誤: - [UIImage fixOrientation]:無法識別的選擇器發送到實例0x174b60 – 2012-03-27 12:12:32