Ios 从NSData加载的UIImage仅在新款iPad3上显示黑色

Ios 从NSData加载的UIImage仅在新款iPad3上显示黑色,ios,ios5,uiimage,nsdata,ipad-3,Ios,Ios5,Uiimage,Nsdata,Ipad 3,我有一个通用的二进制应用程序,目前在iTunes上发布,可以在iPhone3、4、4S和iPad2上正常运行,在iOS 4.x到5.1上运行,但在运行iOS 5.1的新iPad(3)上显示黑色UIImage 还有其他人遇到过这种情况吗?有什么建议吗 问题是从NSData加载的UIImage显示为黑色 我最初认为NSData可能为零或不可读,因此我添加了UIAlert&NSLog以输出NSData长度和UIImage大小属性(假设将数据成功读取到UIImage中会产生合理的大小值)。在UIAler

我有一个通用的二进制应用程序,目前在iTunes上发布,可以在iPhone3、4、4S和iPad2上正常运行,在iOS 4.x到5.1上运行,但在运行iOS 5.1的新iPad(3)上显示黑色UIImage

还有其他人遇到过这种情况吗?有什么建议吗

问题是从NSData加载的UIImage显示为黑色

我最初认为NSData可能为零或不可读,因此我添加了UIAlert&NSLog以输出NSData长度和UIImage大小属性(假设将数据成功读取到UIImage中会产生合理的大小值)。在UIAlert中一切看起来都正常

// MyView.m

- (NSData*)getImageData

{      

     Screening *screen = [[Model sharedInstance] screenInProgress];

     return screen.anteriorImage;  // returns the NSData from the managed 'Screening' object

}


- (void)viewWillAppear:(BOOL)animated

{
     NSData *imagedata = [self getImageData];

     UIImage *image = [UIImage imageWithData:imagedata];

     [clientImageView setImage:image];     /// UIImageView in nib




     /// apply user grid
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];


     if ([defaults integerForKey:@"com.ikonetics.posture.gridoverlay"] >= 0) {     

          UIImageView *grid = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"grid.png"]];

          [grid setBackgroundColor:[UIColor clearColor]];

          [grid setAlpha:0.6f];

          [grid setFrame:clientImageView.frame];

          [screenshotWrapper addSubview:grid];     // screenshotWrapper is a UIView in xib arranged as a parent to other views

          [grid release];

     }


     NSString *note = [NSString 

                           stringWithFormat:@"NSData length: %d \nUIImage size: %@ \nUIImage scale: %1.f \nClientImage info: %@"

                           , [imagedata length]

                           , NSStringFromCGSize(image.size)

                           , image.scale

                           , [clientImageView description]

                           ];



     NSLog(@"debug note: %@ ", note);

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"DEBUG INFO" 

                                                                 message:note

                                                               delegate:nil

                                                    cancelButtonTitle:@"OK"

                                                    otherButtonTitles:nil];

     [alert show];   

     [alert release];



}



// Screening.h

@interface Screening : NSManagedObject


@property (nonatomic, retain) NSData * anteriorImage;     // this data is stored elsewhere using UIImageJPEGRepresentation(image, 0.8);
...
@end
iPad 3显示UIAlertView的屏幕截图,您可以看到NSData有长度,UIImage有大小,UIImageView(ClientImage)有合理的边框,网格覆盖UIImage显示正确,如预期

  • 返回的NSData具有长度,并且不是
    nil
    (下面是187433)
  • UIImage能够解析数据并构建图像,通过大小和比例属性(784980)证明

最后,这已经在禁用了
///apply user grid
选项的情况下进行了测试,因此覆盖png甚至没有实例化,因为该代码块没有运行。黑色图像问题仍然存在

其他人对显示黑色UIImage而不是实际图像的UIImageView有问题吗?关于如何修复代码,使其在iPad3上正常工作,您有什么想法吗

谢谢

编辑-更多调试信息:

我把NSData(imagedata)写进了一封电子邮件,这样我就可以在设备上查看它了。我想知道图像本身是否为空白/黑色,并了解到数据在从设备上保存时正确显示为图像(不是空白)

因此,加载到UIImage&UIImageView中的NSData显示为黑色。。。但当附加到电子邮件时,它会正确显示图像

此外,我希望确保视图的层次结构按预期显示;检查我的图像是否不在其他视图下。从ViewController的
视图开始
,我记录了
递归描述
,了解到iPad3上的视图层次结构与iPad2相匹配,这正是我所期望的

新调试代码:

NSString *note = [NSString 
                  stringWithFormat:@"NSData length: %d \nUIImage size: %@ \nUIImage scale: %1.f \nRecursive info: %@"
                  , [imagedata length]
                  , NSStringFromCGSize(image.size)
                  , image.scale
                  , [[self view] recursiveDescription]
                  ];

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"Debug email"];
[mailViewController setMessageBody:note isHTML:NO];
[mailViewController addAttachmentData:imagedata mimeType:@"image/jpg" fileName:@"imagedata.jpg"];

[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
最后,这里是2和3设备的递归日志信息:

iPad 2日志:

NSData length: 123254 
UIImage size: {800, 960} 
UIImage scale: 1 
Recursive info: <UIView: 0x10a91620; frame = (0 0; 768 960); autoresize = W+H; layer = <CALayer: 0x10a91650>>
   | <UIScrollView: 0x10a90a10; frame = (0 0; 768 960); clipsToBounds = YES; autoresize = RM+TM; layer = <CALayer: 0x10a90bb0>; contentOffset: {0, 0}>
   |    | <UIView: 0x10a90be0; frame = (0 0; 1536 1920); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x10a90c10>>
   |    |    | <UIView: 0x10a90c40; frame = (384 480; 768 960); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x10a90c70>>
   |    |    |    | <UIImageView: 0x10a908f0; frame = (0 0; 768 960); opaque = NO; autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10a90930>>
   |    |    |    | <LineView_iPad: 0x10a90ce0; frame = (0 0; 768 960); autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10a90d20>>
   |    |    |    | <PointView_iPad: 0x10a90dd0; frame = (0 0; 768 960); autoresize = LM+RM+TM+BM; layer = <CALayer: 0x10a90e20>>
   |    |    |    | <UIImageView: 0x10a96480; frame = (0 0; 768 960); alpha = 0.6; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x10a966e0>>
   | <UIView: 0x10a91680; frame = (-10 750; 220 220); autoresize = RM+TM; layer = <CALayer: 0x10a916b0>>
   |    | <UIImageView: 0x10a916e0; frame = (0 0; 220 220); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x10a91720>>
   |    | <UIImageView: 0x10a91480; frame = (10 10; 200 200); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10a914c0>>
   |    | <UIImageView: 0x10a91840; frame = (102 102; 16 16); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10a91880>>
NSData长度:123254
UIImage大小:{800960}
图像比例:1
递归信息:
| 
|    | 
|    |    | 
|    |    |    | 
|    |    |    | 
|    |    |    | 
|    |    |    | 
| 
|    | 
|    | 
|    | 
iPad 3日志:

NSData length: 166252
UIImage size: {784, 980}
UIImage scale: 1
Recursive info: <UIView: 0xc669470; frame = (0 0; 768 980); autoresize = W+H; layer = <CALayer: 0xc667550>>
 | <UIScrollView: 0x33d410; frame = (0 20; 768 960); clipsToBounds = YES; autoresize = RM+TM; layer = <CALayer: 0x325840>; contentOffset: {0, 0}>
 |    | <UIView: 0x308630; frame = (0 0; 1536 1920); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xc666f40>>
 |    |    | <UIView: 0x318970; frame = (384 480; 768 960); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xc682a70>>
 |    |    |    | <UIImageView: 0xc66cd60; frame = (0 0; 768 960); opaque = NO; autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xc672c00>>
 |    |    |    | <LineView_iPad: 0x301680; frame = (0 0; 768 960); autoresize = LM+RM+TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x329fa0>>
 |    |    |    | <PointView_iPad: 0xc6841b0; frame = (0 0; 768 960); autoresize = LM+RM+TM+BM; layer = <CALayer: 0xc672b10>>
 |    |    |    | <UIImageView: 0xc588b70; frame = (0 0; 768 960); alpha = 0.6; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xc589500>>
 | <UIView: 0x324330; frame = (-10 770; 220 220); autoresize = RM+TM; layer = <CALayer: 0xc687970>>
 |    | <UIImageView: 0xc665b80; frame = (0 0; 220 220); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x321490>>
 |    | <UIImageView: 0x314e50; frame = (10 10; 200 200); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xc684f30>>
 |    | <UIImageView: 0x63d220; frame = (102 102; 16 16); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xc580d90>>
NSData长度:166252
UIImage大小:{784980}
图像比例:1
递归信息:
| 
|    | 
|    |    | 
|    |    |    | 
|    |    |    | 
|    |    |    | 
|    |    |    | 
| 
|    | 
|    | 
|    | 

尽管这篇文章太长了,我真的希望有人能想到任何可能导致这个问题的东西…

这似乎是iOS的一个bug。这是解决方法:

  • 在Interface Builder中,将UIImageView背景纹理更改为任何颜色
就这样

我在调试过程中偶然发现了这一点,当时我随意地翻转开关试图让有趣的事情发生。我的代码/应用程序未使用UIImageView的背景色,其属性尚未调整。。。曾经

在上面的代码中,
UIImageView
“clientImageView”的背景设置为纹理“View-Flipside-background-Color”。将该纹理设置为背景时,加载的UIImage拒绝显示。将背景纹理更改为除“Flipside”之外的任何内容,UIImage将按预期显示

  • 我们所做的唯一更改是界面生成器中UIImageView的背景色属性
  • 唯一出现错误的地方是运行iOS 5.1的iPad3硬件
  • 它每次都失败,并且是可复制的
  • 在iPhone4、4S、iPad2和iOS 4.x到5.1上也进行了测试
报告给苹果的Bug ID为#11080928