convert UIImage to NSData and back to UIImage
Try With this:
Use this for convert UIImage
to NSData
.
NSData *imagedata = UIImagePNGRepresentation(thumbnail);
Try this for image data convert back to UIImage
UIImage *image= [UIImage imageWithData:imagedata];
in Swift version:
let imageData = image!.pngData()
let imageFromData = UIImage(data: imageData)
See: https://developer.apple.com/documentation/uikit/uiimage/1624096-pngdata
To convert UIImage
to NSData
, use either UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality)
or UIImagePNGRepresentation(UIImage *image)
To convert NSData
to UIImage
, use [UIImage imageWithData:imageData]
So your example could look like this:
cell.textLabel.text = [[offlineImageListArray objectAtIndex:indexPath.row] imageName];
UIImage *thumbnail = [self retrieveImageFromDevice:[[offlineImageListArray objectAtIndex:indexPath.row] imageName]];
NSData* data = UIImagePNGRepresentation(thumbnail);
ImageData *imageDataObject = [[ImageData alloc] initWithImageId:[[offlineImageListArray objectAtIndex:indexPath.row]imageId] imageName:[[offlineImageListArray objectAtIndex:indexPath.row] imageName] imageData:data];
[imagesArray addObject:imageDataObject];
References: https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html