I have a UIImageView
whose image gets set via UIImagePicker
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPi
Here is what I have done and its working for storing to nsdata.
[productTypeSub setValue:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]] forKey:@"imgSmall"];
and loading to image with this code
ImgProductType.image= [[UIImage alloc] initWithData:productTypeSub.imgSmall];
You can convert a UIImage to NSData like this:
If PNG image
UIImage *image = [UIImage imageNamed:@"imageName.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
If JPG image
UIImage *image = [UIImage imageNamed:@"imageName.jpg"];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
You can store it in CoreData like so (this is one possible useful solution):
[newManagedObject setValue:imageData forKey:@"image"];
You can load the data from CoreData like this:
NSManagedObject *selectedObject = [[self yourFetchCOntroller] objectAtIndexPath:indexPath];
UIImage *image = [UIImage imageWithData:[selectedObject valueForKey:@"image"]];
// Set the image to your image view
yourimageView.image = image;