0

I have a prepareForSegue that passes an image like this to the next viewController

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  WizardPreview *controller = [segue destinationViewController];
  controller.myPicture = myPicture;
}

On the viewWillAppear of the viewController being presented I have a like like this

CGImageRef imageRef = [self.myPicture CGImage];

the result is nil

The strange part is that self.myPicture is not nil, but self.myPicture.CGImage is.

Any reason for that?

NOTE: myPicture is not nil when it is passed and even from viewWillAppear, I test and I see that self.myPicture is not nil.

NOTE 2: this is a code compiled for iOS 7 running on an iPhone with iOS 8.

Duck
  • 34,902
  • 47
  • 248
  • 470

1 Answers1

1

You haven't posted enough code to say for sure. The three most likely options are:

  1. If myPicture is nil in the prepareForSegure:sender: method
  2. If WizardPreview's myPicture property is weak
  3. If the UIImage is not backed by a CGImage (for example, if it's backed by a CIImage)

If #3 is true, you can create a CGImage directly from a CIImage (sample code here).

Community
  • 1
  • 1
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • 1. myPicture is not nil when passed and even from `viewWillAppear`. 2. no it is strong. 3. what do you mean? ... I have added more info to the question. The strange part is `self.myPicture` is not nil... `self.myPicture.CGImage` is. – Duck Sep 16 '14 at 19:06
  • 1
    Not all `UIImage`s have a `CGImage`. – Aaron Brager Sep 16 '14 at 19:11
  • Now you crumbled my world... what??????????? how do I fix that? This UIImage was created from a CCImage. – Duck Sep 16 '14 at 19:36
  • Is the `CIImage` property nil also? – Aaron Brager Sep 16 '14 at 19:38
  • this phrase of yours "Not all UIImages have a CGImage", solved the problem. I changed the code to create a CGImage directly from the CIImage and it worked. Please add this phrase to your answer, so I can accept that. – Duck Sep 16 '14 at 19:55