title: Why UIImageJPEGRepresentation and UIImagePNGRepresentation increase data size?
body: <p>Doing a image scaling to have image limit in 320x480, so <code>w</code> &lt;= 320 and <code>h</code> &lt;= 640. But after conversion to data and back conversion to image I get a twice as big image as it was originally. Why? How can I avoid? Should use 160x320 size to get the required size?</p>
  
  <pre><code>let s = CGSize(width: w, height: h)
  UIGraphicsBeginImageContextWithOptions(s, false, 0.0);
  image.draw(in: CGRect(x: 0, y: 0, width: w, height: h))
  let newImage = UIGraphicsGetImageFromCurrentImageContext()
  UIGraphicsEndImageContext();
  
  let data2 = UIImageJPEGRepresentation(newImage!, 1.0)!
  let image3 = UIImage(data: data2)
  </code></pre>
  
  <hr>
  
  <blockquote>
    <p>(lldb) po newImage!.size ▿ (320.0, 213.5)
      - width : 320.0
      - height : 213.5</p>
    
    <p>(lldb) po image3!.size ▿ (640.0, 427.0)
      - width : 640.0
      - height : 427.0</p>
  </blockquote>