11

I have an error when I tried to create a UIImageView. Look at this code :

UIImage* backgroundPanel = [[UIImage imageNamed:@"loginPanelBackground.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(90, 0, 149, 416)];

self.connexionBackgroundImgView = [[UIImageView alloc] initWithImage:backgroundPanel];
self.connexionBackgroundImgView.frame = CGRectMake(0, 0, 416, 390); // THIS LINE PROVOC THE INVALID CONTEXT
[self.connexionView insertSubview:self.connexionBackgroundImgView aboveSubview:self.connexionToCreationCompteView];

It throws this error in the log :

<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextSetBlendMode: invalid context 0x0
<Error>: CGContextSetAlpha: invalid context 0x0
<Error>: CGContextTranslateCTM: invalid context 0x0
<Error>: CGContextScaleCTM: invalid context 0x0
<Error>: CGContextGetCTM: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextClipToRect: invalid context 0x0
<Error>: CGContextDrawTiledImage: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextGetCTM: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextClipToRect: invalid context 0x0
<Error>: CGContextDrawTiledImage: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextGetCTM: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextClipToRect: invalid context 0x0
<Error>: CGContextDrawTiledImage: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0

I had this error only on the iPad, not with the Simulator, I don't understand.. :/

seb
  • 401
  • 1
  • 4
  • 12
  • Are you using any custom drawing code? like by using CGContext and all? – iDev Nov 01 '12 at 19:31
  • Also try changing self.connexionBackgroundImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 416, 390)]; [self.connexionBackgroundImgView setImage:backgroundPanel]; Actually it shouldnt make much difference. But still you can try. – iDev Nov 01 '12 at 19:33
  • Are you using any custom drawing? implementing CGContext somewhere? – iDev Nov 01 '12 at 21:50
  • See the answer here: http://stackoverflow.com/questions/10695258/how-do-i-capture-uiimage-of-complete-contents-of-uitableview-uiscrollview-and – eliajf Nov 02 '12 at 22:17
  • Thanks eliajf, can you post your comment as an answer. Then, I'll accept it as the right one ! – seb Nov 03 '12 at 12:21

4 Answers4

40

I had this problem until I found out that my cap inset argument to resizableImageWithCapInsets: was wrong — it didn't leave any un-capped area at all (you need at least 1x1 pixel not covered by a cap). So make sure that:

(insets.left + insets.right) < width

and

(insets.top + insets.bottom) < height

neon1
  • 716
  • 5
  • 5
0

The Simulator is case-insensitive. The device is case-sensitive. The png is named correctly? Maybe it is 'Login' with a capital L.

Masa
  • 3,241
  • 1
  • 16
  • 12
  • The image is displayed correctly both on Simulator and iPad. The log changes nothing but I want to know why I have this error :/ – seb Nov 01 '12 at 19:20
0

See the answer here : How do I capture UIImage of complete contents of UITableView / UIScrollView and make it work on an ios device

Thanks eliajf !

Community
  • 1
  • 1
seb
  • 401
  • 1
  • 4
  • 12
0

I still can't comment due to low rep. However I'd like to add to neon1's answer which helped me a lot.

You also need to make sure that all of the insets are greater than zero.

insets.left > 0

insets.top > 0

insets.right > 0

insets.bottom > 0

Almighty
  • 835
  • 8
  • 16