我有一些简单的代码问题.用相机拍摄或拍摄的照片会旋转.起初我认为它是UIView中的一个设置,但是当我使用CG
ImageRef将传递的UI
Image复制到另一个UIImage时会发生这种情况.我是这样做的,因为这是确保我使用副本的最简单方法.如果我搞砸了,请更正此代码.
代码:
- (id)initWithImage:(UIImage *)image {
if ((self = [super init]) && (image != nil)) {
CGImageRef tmpImageRef = [image CGImage];
puzzle = [[UIImage alloc] initWithCGImage:tmpImageRef];
}
return self;
}
调试器:
This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys001
Loading program into debugger…
sharedlibrary apply-load-rules all
Program loaded.
target remote-mobile /tmp/.XcodeGDBRemote-25694-49
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
run
Running…
[Switching to thread 11523]
[Switching to thread 11523]
Re-enabling shared library breakpoint 1
Re-enabling shared library breakpoint 2
continue
2010-07-13 15:09:17.159 Golovomka[693:307] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
2010-07-13 15:09:17.172 Golovomka[693:307] Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate
Current language: auto; currently objective-c
(gdb) print (CGSize)[image size]
$1 = {
width = 1536,
height = 2048
}
(gdb) n
28 puzzle = [[UIImage alloc] initWithCGImage:tmpImageRef];
(gdb)
31 return self;
(gdb) print (CGSize)[puzzle size]
$2 = {
width = 2048,
height = 1536
}
(gdb)
第一个打印在CGIMageRef实例化行上.任何帮助感激不尽.正如我所说,这不会发生在模拟器中,只有当我将代码部署到真实设备时才会发生.
请注意这篇文章曾经说过,问题只发生在设备上调试而不是模拟器中.我已经将用我的iphone 3gs上的相机拍摄的照片复制到模拟器上,并且出现了完全相同的问题.因此,如果你有一个2048×1536的图片,你应该可以在SIM卡中复制它.
最佳答案 当你从UIImage中提取CGImage时,UIImage有一个你忽略的方向属性.你应该这样做:
if (self = [super init]) {
puzzle = image;
}