title: When i am using UIImagePNGRepresentation or UIImageJPEGRepresentation for converting UIImage into NSdata, the image size is too much increased
body: <p><strong>When i am using UIImagePNGRepresentation or UIImageJPEGRepresentation for converting UIImage into NSdata, the image size is too much increased.</strong>  </p>
  
  <p>Steps to Reproduce:</p>
  
  <p>1)Open Xcode and select new project as single view based application </p>
  
  <p>2)Open ViewController.xib and add two buttons named as i)Test Online Image ii)Test Local image</p>
  
  <p>3)Add two IBActions </p>
  
  <pre><code>  i)  -(IBAction)ClickLocalImageTest:(id)sender;
  
    ii) -(IBAction)ClickOnLineImageTest:(id)sender;
  </code></pre>
  
  <p>4)Connect "Test Online Image" to "<code>-(IBAction)ClickOnLineImageTest:(id)sender</code>"</p>
  
  <p>and "Test Local image" to "  <code>-(IBAction)ClickLocalImageTest:(id)sender</code>;"</p>
  
  <p>5)impalement "<code>-(IBAction)ClickLocalImageTest:(id)sender</code>" method like as following </p>
  
  <pre><code>- (IBAction)ClickLocalImageTest:(id)sender {
      NSLog(@"*************Test Local Image****************\n");
      NSString *path=[[NSBundle mainBundle] pathForResource:@"hero_ipad_retina" ofType:@"jpg"];
      NSLog(@"Before testing image size is :&lt;---- %u kb",[[NSData dataWithContentsOfFile:path] length]/1024);
      UIImage *img  = [UIImage imageNamed:@"hero_ipad_retina.jpg"];
       NSLog(@"UIImagePNGRepresentation: image size is----&gt;: %u kb",[UIImagePNGRepresentation(img) length]/1024);
      NSLog(@"UIImageJPEGRepresentation with scale 1.0: image size is----&gt;: %u kb \n",[UIImageJPEGRepresentation(img, 1.0) length]/1024);
      NSLog(@"*************Completed test****************\n\n\n\n");
  } 
  </code></pre>
  
  <p>6) impalement "<code>- (IBAction)ClickOnLineImageTest:(id)sender</code>" method as following </p>
  
  <pre><code>- (IBAction)ClickOnLineImageTest:(id)sender {
       NSLog(@"*************Test Online Image****************\n");
  NSLog(@"Before testing image size is :&lt;---- %u kb",[[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://images.apple.com/home/images/hero_ipad_retina.jpg"]] length]/1024);
  UIImage *img  = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://images.apple.com/home/images/hero_ipad_retina.jpg"]]];
  NSLog(@"UIImagePNGRepresentation: image size is----&gt;: %u kb",[UIImagePNGRepresentation(img) length]/1024);
  NSLog(@"UIImageJPEGRepresentation with scale 1.0: image size is----&gt;: %u kb \n",[UIImageJPEGRepresentation(img, 1.0) length]/1024);
  NSLog(@"*************Completed test****************\n\n\n\n");
  }
  </code></pre>
  
  <p>7)Please download "hero_ipad_retina.jpg" image from <a href="http://images.apple.com/home/images/hero_ipad_retina.jpg">here</a> and save in your resources named as "hero_ipad_retina.jpg"</p>
  
  <p>7)Now run this project on Xcode 4.0 later and IOS3.0 above SDK</p>
  
  <p>**</p>
  
  <pre><code>Expected Results:
  1)Click on "Test Online Image" button result should be as following 
  *************Test Online Image****************
  Before testing image size is :&lt;---- 78 kb
  UIImagePNGRepresentation: image size is----&gt;: 78 kb
  UIImageJPEGRepresentation with scale 1.0: image size is----&gt;: 78 kb
  *************Completed test****************
  2)1)Click on "Test Local image" button result should be as following
  *************Test Local Image****************
  Before testing image size is :&lt;---- 78 kb
  UIImagePNGRepresentation: image size is----&gt;: 78 kb
  UIImageJPEGRepresentation with scale 1.0: image size is----&gt;: 78 kb 
  *************Completed test****************
  Actual Results:
  1)Click on "Test Online Image" button result should be as following 
  *************Test Online Image****************
  Before testing image size is :&lt;---- 78 kb
  UIImagePNGRepresentation: image size is----&gt;: 480 kb
  UIImageJPEGRepresentation with scale 1.0: image size is----&gt;: 180 kb
  *************Completed test****************
  2)1)Click on "Test Local image" button result should be as following
  *************Test Local Image****************
  Before testing image size is :&lt;---- 78 kb
  UIImagePNGRepresentation: image size is----&gt;: 480 kb
  UIImageJPEGRepresentation with scale 1.0: image size is----&gt;: 180 kb 
  *************Completed test******************
  </code></pre>
  
  <p>My Question :</p>
  
  <p><strong>why it is increasing its size ? and what is the optimized way to convert image to NSData?</strong></p>
  
  <p>Notes:
  Please download "hero_ipad_retina.jpg" image from <a href="http://images.apple.com/home/images/hero_ipad_retina.jpg">here</a> and save in your resources </p>