-1

I have one UIImage which I want to deep copy to another (so that I may add it to an NSMUtableArray of images)

I cannot get it to deep copy, I have looked at zones and such but this no luck.

This is what I have trieD:

_incrementalImage = UIGraphicsGetImageFromCurrentImageContext();

UIImage *imgcpy = [[UIImage allocWithZone:[_incrementalImage zone]];
[stack addObject:imgcpy];

Basically I need a copy of incrementalImage onto stack that won't change if _incrementalImage or currentImageContext changes.

ddoor
  • 5,819
  • 9
  • 34
  • 41
  • 1
    Does the answer to this question help? (I think a `CGImageRelease()` is missing, but anyway): http://stackoverflow.com/questions/3867980/how-do-i-make-an-exact-copy-of-a-uiimage-returned-from-a-uiimagepickercontroller – trojanfoe Jan 22 '14 at 15:09
  • 1
    Possible duplicate of [Making deep copy of UIImage](http://stackoverflow.com/questions/4002040/making-deep-copy-of-uiimage) – Cameron Lowell Palmer Feb 06 '16 at 22:05

1 Answers1

2
UIImage *image1 = [UIImage imageNamed:@"someImage"];
UIImage *image2 = [UIImage imageWithCGImage:image1.CGImage];
Dávid Kaszás
  • 1,877
  • 1
  • 16
  • 20