-1

I'm developing an app, where I can apply filters on an image.
I want to create an undo button which resets the original image in the imageView.
The solution is that I just save the original image in it's own UIImage object before I apply any filters to it. This way I can just go back to that in my undo method.

Does somebody know how I can do this?

user3550084
  • 71
  • 2
  • 9
  • possible duplicate of [iOS download and save image inside app](http://stackoverflow.com/questions/6238139/ios-download-and-save-image-inside-app) – dandan78 Apr 24 '14 at 12:21

2 Answers2

0

Take a look at the docs here: https://developer.apple.com/library/ios/documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html

You can do what you want with UIImagePNGRepresentation().

Then to re-read: imageWithContentsOfFile:

mprivat
  • 21,582
  • 4
  • 54
  • 64
0

Get Image from disk . Suppose image stored in document directory.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *yourImgPath = [documentsDirectory stringByAppendingPathComponent:@"1.png"];

UIImage *originalImage = [UIImage imageWithContentsOfFile:yourImgPath];

Create tempImage from originalImage

UIImage *tempImage = originalImage;

Appy filters on tempImage

EDIT : How to save then below is method to save in document directory.

- (BOOL)saveImageInDocDir:(UIImage *)image withImagename:(NSString *)strImgName {
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:strImgName];
  NSData *imageData = UIImagePNGRepresentation(image);
  BOOL isSaved = [imageData writeToFile:savedImagePath atomically:YES];   
  return isSaved;
}

You can also use NSTempraryDirectory to save images as its safe from cloud backup

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132