Tuesday, April 23, 2013

UIImage initWithData example ios


initWithData:

Initializes and returns the image object with the specified data.
- (id)initWithData:(NSData *)data
Parameters
data
The data object containing the image data.
Return Value of [UIImage initWithData]
An initialized UIImage object, or nil if the method could not initialize the image from the specified data.
Discussion of [UIImage initWithData]
The data in the data parameter must be formatted to match the file format of one of the system’s supported image types.
Example of [UIImage initWithData]
- (UIImageView*) ldPageView{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool
NSError *error;
NSData *imData = [NSData dataWithContentsOfURL:ldPageRef options:NSDataReadingUncached error:&error];
UIImage *im = [[UIImage alloc] initWithData:imData];
ldView = [[UIImageView alloc] initWithImage:im] ;
[ldView setFrame:pageRect];
[pool release];  // Release the objects in the pool.
return ldView;
}