<error>:CGImageCreate:图像大小无效:0 x 0 </error>

时间:2014-06-02 12:54:45

标签: ios objective-c facebook cocoa-touch slcomposeviewcontroller

  

在给出重复标记之前,请阅读我的整个问题:

我知道可能有很多与我的头衔有关的问题,但问题不同。

我正在使用Mac OS X 10.9.3和Xcode 5.1.1

在我的应用中,我只是想在Facebook和Twitter上分享图片,网址链接和一些描述,所以我使用SLComposeViewController,我的代码在下面。

-(void)btnShareTapped:(UIButton *)sender
{
  if(sender.tag == 100)
    [self shareProductContentOnTwitterORFB:@"Facebook"];
  else 
    [self shareProductContentOnTwitterORFB:@"Twitter"];   
}

方法体:

-(void) shareProductContentOnTwitterORFB:(NSString *) shareON
{
    SLComposeViewController *shareKit =  nil; // also tried with [[SLComposeViewController alloc] init];
    if([shareON isEqualToString:@"Twitter"])
        shareKit = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
    else
        shareKit = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [shareKit setInitialText:@"My Description Text."];
    [shareKit addImage:[UIImage imageNamed:@"boston-shopping.jpg"]]; // I also tried with .png image
    [shareKit addURL:[NSURL URLWithString:@"www.google.com"]];
    //[self.view.window.rootViewController presentViewController:shareKit animated:YES completion:nil];
    [self presentViewController:shareKit animated:YES completion:nil]; /// I also tried with above comment.
}

执行上述代码后,SLComposeViewController将在我的控制台中打开

<Error>: CGImageCreate: invalid image size: 0 x 0.

仅显示 Facebook 并获得完全相同的问题Look at this question. 我确定我的图像不是nil,我已经检查过了。

上面的问题说 -

  

这个错误似乎在新版本的iOS(6.0.1)中得到修复至少我自上次升级以来一直运作良好。

但是我正在测试 iOS 6.1 ,我仍然遇到同样的问题,并且在 iOS 7.0和7.1 中,控制台中出现错误消息(<Error>: CGImageCreate: invalid image size: 0 x 0.不显示但我无法在 Facebook和Twitter 中设置应用程序。
有什么问题?哪里错了?这是苹果虫吗? 请提出你的建议。

2 个答案:

答案 0 :(得分:1)

在我调用[self presentViewController:shareKit animated:YES completion:nil];

后,请查看此堆栈跟踪
* thread #1: tid = 0x199f3, 0x0026a871 CoreGraphics`CGPostError, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x0026a871 CoreGraphics`CGPostError
    frame #1: 0x0021bfc0 CoreGraphics`CGImageCreate + 296
    frame #2: 0x00458ea5 UIKit`_UICreateCGImageFromCARenderServerBuffer + 201
    frame #3: 0x007e7b0e UIKit`-[UISnapshotView captureSnapshotRect:fromView:withSnapshotType:] + 1712
    frame #4: 0x008fdfa7 UIKit`-[_UIRemoteViewController _snapshotAndRemoveTextEffectsRemoteView] + 337
    frame #5: 0x008fe064 UIKit`-[_UIRemoteViewController _applicationWillResignActive:] + 33
    frame #6: 0x00f9a4f9 Foundation`__57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 40
    frame #7: 0x014e50c5 CoreFoundation`___CFXNotificationPost_block_invoke_0 + 85
    frame #8: 0x0143fefa CoreFoundation`_CFXNotificationPost + 2122
    frame #9: 0x00ecebb2 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 98
    frame #10: 0x0041abb1 UIKit`-[UIApplication _deactivateForReason:notify:] + 381
    frame #11: 0x0041ac3d UIKit`-[UIApplication _deactivateForReason:] + 48
    frame #12: 0x0041cfd4 UIKit`_alertItemStateChanged + 73
    frame #13: 0x014e52e3 CoreFoundation`__CFNotificationCenterAddObserver_block_invoke_0 + 163
    frame #14: 0x014e53a0 CoreFoundation`____CFXNotificationPostToken_block_invoke_0 + 176
    frame #15: 0x0144a920 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
    frame #16: 0x0140dd31 CoreFoundation`__CFRunLoopDoBlocks + 257
    frame #17: 0x01431c51 CoreFoundation`__CFRunLoopRun + 2273
    frame #18: 0x01430f44 CoreFoundation`CFRunLoopRunSpecific + 276
    frame #19: 0x01430e1b CoreFoundation`CFRunLoopRunInMode + 123
    frame #20: 0x01dcb7e3 GraphicsServices`GSEventRunModal + 88
    frame #21: 0x01dcb668 GraphicsServices`GSEventRun + 104
    frame #22: 0x0041dffc UIKit`UIApplicationMain + 1211
    frame #23: 0x00002f3d iostest`main(argc=1, argv=0xbffff0d0) + 141 at main.m:16

我尝试在我的示例项目中运行您的代码,我发现了这些:

  • 错误消息是在[self presentViewController:shareKit animated:YES completion:nil];之后和模态shareKit视图出现之前打印的。
  • 错误讯息来自CGPostError中的CoreGraphics
  • 我认为由于-[UISnapshotView captureSnapshotRect:fromView:withSnapshotType:]而发生此错误。
  • 我试着评论你的这一行[shareKit addImage:[UIImage imageNamed:@"boston-shopping.jpg"]];,但我仍然收到错误消息。所以,错误不是因为你的代码。

在我看来,我认为你得到的错误信息是因为UISnapshotView试图拍摄当前屏幕的快照,但是那里没有任何东西或者方法中存在一些错误。因此,它将错误的width = 0 & height = 0参数传递给导致错误的CGImageCreate

所以,请放心,这不是你的错误。只是忽略它。

答案 1 :(得分:-1)

亲自尝试创建CGImageRef对象。您可以替换该行:

[shareKit addImage:[UIImage imageNamed:@"boston-shopping.jpg"]];

用这个:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"boston-shopping" ofType:@"jpg"];
CGDataProviderRef source = CGDataProviderCreateWithFilename([filePath cStringUsingEncoding:NSUTF8StringEncoding]);
CGImageRef imageRef = CGImageCreateWithJPEGDataProvider(source,
                                                        NULL,
                                                        true,
                                                        kCGRenderingIntentDefault);
[shareKit addImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
相关问题