NSData and its mutable subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers. Data objects let simply allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation Objects.
NSData creates static Data Objects, and NSMutableData creates dynamic data objects. NSData and NSMutableData are typically used for data storage and are also useful in Distributed Objects applications, where data contained in data objects can be copied or moved between applications.
The size of the data is subject to a theoretical limit of about 8 ExaBytes (in practice, the limit should not be a factor).
Subscribe to our youtube channel to get new updates..!
UIImage *IMG =[UIImage imageNamed:@ “1.jpg”]; NSLog (@ “img is %@”,img);
[ Related Article: What is Swift ]
// How to convert image object to data:
NSData*data = UIImage JPEG Representation (img,1); NSLog(@ “ image data is %@”,data);
// Converting the png Image object to data:
NSData *data2 = UIImage PNGRepresentation (img); NSLog (@ “ png Image data is %@”, data2);
[ Related Article: IOS Development Interview Questions & Answers ]
//How to know the size of an image:
Int size = [data length]; If (size /1024>0) NSLog (@ “ image size is %d kb”, size/1024); else NSLog (@ “image size is %d Bytes , size);
//How to convert data to image object:
UIImage *img2 = [UIImage ImageWithData : data]; NSLog(@ “the image is %@”,img2);
//How to Append Data:
NSMutableData*mutData= [[NSMutableData alloc]init]; [MutData appendData : data]; NSLog (@ “the mutable data is %@”, mutData);
//Getting URL image as Data:
NSData *URL data = [NSData datawithContentsOfURL : [NSURL URLwithString:@https://www.Cnet.co.uk/i/c/blg/cat/mobiles/ios5.jpg”]]; UIImage *URLImage =[UIImage ImageWithData : URL data]; NSLog (@ “data length is %d kb ,[URL data length]1024];
//Setting the image as a background image for view:
self view background color=[UIColor Color with PatternImage: URLImage];