Iphone CGImageRef到UIImage在iOS 4模拟器或设备上旋转照片调试

Iphone CGImageRef到UIImage在iOS 4模拟器或设备上旋转照片调试,iphone,objective-c,uiimage,ios4,Iphone,Objective C,Uiimage,Ios4,我对一些简单的代码有问题。相机拾取或拍摄的照片都会旋转。起初我以为这是UIView中的一个设置,但当我使用CGImageRef将传入的UIImage复制到另一个UIImage时,就会发生这种情况。我这样做是因为这是确保我使用副本的最简单方法。如果我搞砸了,请更正这个密码 守则: - (id)initWithImage:(UIImage *)image { if ((self = [super init]) && (image != nil)) { CGIm

我对一些简单的代码有问题。相机拾取或拍摄的照片都会旋转。起初我以为这是UIView中的一个设置,但当我使用CGImageRef将传入的UIImage复制到另一个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上的相机拍摄的照片复制到模拟器上,同样的问题也发生了。因此,如果您周围有2048x1536 pic,您应该能够在sim卡中复制它。

UIImage的方向属性在您从UIImage提取CGImage时被忽略。您应该这样做:

if (self = [super init]) {
    puzzle = image; 
}

这确实保持了方向。我确实发现这篇文章涵盖了类似的内容。当我在代码崩溃之前这样做的时候,我认为这是因为后来图像被发布了。现在的情况似乎不是这样,所以当我在谷歌上搜索一个使用imageref方法得到的解决方案时,我一定是搞砸了别的事情;我觉得这对现代语言来说有点垃圾。非常感谢。作为进一步的说明,在以后的开发中,我确实在适当的时候翻译和旋转了图像,以消除这个问题,因为在不同的库和系统中处理方向数据变得很痛苦。e、 核心图形、opencv、位操作。