I wish to compress the image before storing it as an NSData object.
Below is the code, that helps me take NSData object of an Image.
NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library1 = [[ALAssetsLibrary alloc] init];
[library1 assetForURL:referenceURL resultBlock:^(ALAsset *asset)
{
int byteArraySize = asset.defaultRepresentation.size;
NSMutableData* rawData = [[NSMutableData alloc]initWithCapacity:byteArraySize];
void* bufferPointer = [rawData mutableBytes];
NSError* error=nil;
[asset.defaultRepresentation getBytes:bufferPointer fromOffset:0 length:byteArraySize error:&error];
if (error) {
NSLog(@"%@",error);
}
rawData = [NSMutableData dataWithBytes:bufferPointer length:byteArraySize];
}
Any Help will be appreciated.
UIImagePickerController does return a compressed image, but you can control the format and compression as well with this built in UIKit function and a related function for PNGs:
You might need to create an NSURL if referenceURL returns a string.