CGImageCreate:无效的图像大小 0 x 0,打开控制中心时

Posted

技术标签:

【中文标题】CGImageCreate:无效的图像大小 0 x 0,打开控制中心时【英文标题】:CGImageCreate: invalid image size 0 x 0, when opening control center 【发布时间】:2013-11-22 13:40:14 【问题描述】:

我正在开发一个带有自定义 UINavigationBar 的选项卡式应用程序。每当我在 ios 模拟器中打开控制中心时,Xcode 中的命令行总是给我以下错误:

CGImageCreate:无效的图像大小 0 x 0。

它出现在每个 ViewController 中,即使是空的。

这可能与自定义 UINavigationBar 或 TabBar 相关吗?

这是我用于标签栏的 appdelegate.m 文件中的代码

    DMFirstViewController *firstViewController = [[DMFirstViewController alloc] init];
    DMSecViewController *secondViewController = [[DMSecViewController alloc] init];
    DMThirdViewController *thirdViewController = [[DMThirdViewController alloc] init];
    DMFourthViewController *fourthViewController = [[DMFourthViewController alloc] init];

    tabController = [[UITabBarController alloc] init];

    NSArray* controllers = [NSArray arrayWithObjects:firstViewController, secondViewController, thirdViewController, fourthViewController, nil];

    tabController.viewControllers = controllers;


    UIImage *unselectedTabFirst = [UIImage imageNamed:@"first_line.png"];
    UIImage *selectedTabFirst = [UIImage imageNamed:@"first_active.png"];

    UIImage *unselectedTabSec = [UIImage imageNamed:@"second_line.png"];
    UIImage *selectedTabSec = [UIImage imageNamed:@"second_active.png"];

    UIImage *unselectedTabThird = [UIImage imageNamed:@"third_line.png"];
    UIImage *selectedTabThird = [UIImage imageNamed:@"third_active.png"];

    UIImage *unselectedTabFourth = [UIImage imageNamed:@"fourth_line.png"];
    UIImage *selectedTabFourth = [UIImage imageNamed:@"fourth_active.png"];


    unselectedTabFirst = [unselectedTabFirst imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    selectedTabFirst = [selectedTabFirst imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    unselectedTabSec = [unselectedTabSec imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    selectedTabSec = [selectedTabSec imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    unselectedTabThird = [unselectedTabThird imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    selectedTabThird = [selectedTabThird imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    unselectedTabFourth = [unselectedTabFourth imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    selectedTabFourth = [selectedTabFourth imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];



    firstViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"first" image:unselectedTabFirst selectedImage:selectedTabFirst];

    secondViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"second" image:unselectedTabSec selectedImage:selectedTabSec];

    thirdViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"third" image:unselectedTabThird selectedImage:selectedTabThird];

    fourthViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"fourth" image:unselectedTabFourth selectedImage:selectedTabFourth];

【问题讨论】:

***.com/questions/14799908/… 是的,确实如此。您应该发布自定义导航以消除错误... 【参考方案1】:

正如 Retro 中的链接所示,这只发生在 iOS 模拟器中。在开发者设备上运行应用程序不会产生此错误。

问题解决了!

【讨论】:

我在 iPad 2 模拟器上看到这种情况,在 iPad Air 2 模拟器上运行是可以的

以上是关于CGImageCreate:无效的图像大小 0 x 0,打开控制中心时的主要内容,如果未能解决你的问题,请参考以下文章

cgimagecreate 正确设置 bytesperrow 但点的强度随着图像大小的变化而不同

Android java.lang.IndexOutOfBoundsException:无效索引0,大小为0

无效的图像路径 - 在键 'CFBundleIcons':'AppIcon29x29' 错误下引用的路径中找不到图像

错误 itms-90122 - 无效的可执行文件大小

为啥使用标准 BMP 位数据的 iphone CGImageCreate 会给出错误的结果?

PHP图像调整大小会切断我的图像