// This is the line which retrieves the current image on the UIView
CGImageRef originalImage = imageView.image.CGImage;
I declare this in a method I use to edit my image which can be called by several buttons.
Is there anyway I can declare this variable globally so it always holds the first image loaded in the UIView? I can then use a copy variable to do all the editing on e.g.
CGImageRef copyImage = originalImage;
I have tried to make it global by declaring it in the header file and instantiate it in the method file however when I try and access the global variable in another method it is as if it hasn’t been made global.
Any advice or better solutions would be greatly appreciated.
It is not entirely clear what you are trying to do, but what I would point out is:
the assignment
will not create a copy of your image; it will simply give you a local variable pointing to the same image as
originalImage; if you modifycopyImage, you also modifyoriginalImage;if you want to make a copy of an CGImage so that you can modify it freely while keeping the original safe, use:
if you want to save your original image as under point 2, simply add a property to your class and initialize it soon after you have got your CGImage in place (e.g., in
viewDidLoad:self.originalImagewill be your original image, while you will be able to freely modifyimageView.image.CGImage.Don’t forget to release the copied image in your dealloc method.
Hope this helps.