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

发布于 2024-09-09 11:00:54 字数 1878 浏览 4 评论 0原文

我对一些简单的代码有疑问。无论是用相机拾取还是拍摄的照片都会旋转。起初我以为这是 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 图片,您应该能够在 sim 中复制它。

I have a problem with some simple code. The photo's, either picked or taken with the camera, are rotated. At first I thought it was a setting in the UIView but it happens when I copy the passed in UIImage to another UIImage using CGImageRef. I did it this way as it was the easiest way to ensure I was using a copy. Correct this code if I've screwed up please.

The code:

- (id)initWithImage:(UIImage *)image {
    if ((self = [super init]) && (image != nil)) {
        CGImageRef tmpImageRef = [image CGImage];
        puzzle = [[UIImage alloc] initWithCGImage:tmpImageRef];
    }

    return self;
}

The debugger:

    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)

The first print is on the CGIMageRef instantiation line. Any help gratefully received. As I said, this does not happen in the simulator and only when I deploy the code to a real device.
Please note this post used to say that the problem only occurred debugging on devices and not in the simulator. I have since copied a photo taken with the camera on my iphone 3gs to the simulator and exactly the same problem occurs. So if you have a 2048x1536 pic lying around you should be able to duplicate this in the sim.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

☆獨立☆ 2024-09-16 11:00:54

UIImage 有一个方向属性,当您从 UIImage 中提取 CGImage 时,您会忽略该属性。你应该这样做:

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

UIImage's have an orientation property that you are ignoring when you extract the CGImage from the UIImage. You should be doing this:

if (self = [super init]) {
    puzzle = image; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文