title: Compressing Images in Iphone programmatically from NSData
body: <p>I wish to compress the image before storing it as an <code>NSData</code> object. </p>
  
  <p>Below is the code, that helps me take <code>NSData</code> object of an Image.</p>
  
  <pre><code>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:&amp;error];
               if (error) {
                   NSLog(@"%@",error);
               }
               rawData = [NSMutableData dataWithBytes:bufferPointer length:byteArraySize];
  }
  </code></pre>
  
  <p>Any Help will be appreciated.</p>