title: Why do UIImages initialized from FileManager data have the wrong scale?
body: <p>I use Alamofire to download images from a request script I wrote. I then save the image to the device and later recall it with the following functions:</p>
  
  <pre><code>    private static func save(image: UIImage, fileName: String) -&gt; String? {
          let fileURL = documentsUrl.appendingPathComponent(fileName)
          if let imageData = UIImageJPEGRepresentation(image, 1.0) {
              do{
                  try imageData.write(to: fileURL) // When the images are downloaded, they seem to have the correct scale set already. Maybe we should verify this
                  if image.scale != UIScreen.main.scale {
                      print("save - image scale: \(image.scale) does not match device scale: \(UIScreen.main.scale)")
                  }
                  print("Saving image to file: \(fileURL)")
                  return fileName // ----&gt; Save fileName
              }
              catch{
                  print("Error info: \(error)")
              }
          }
          print("Error saving image")
          return nil
      }
  
  
      private static func loadImage(_ fileName: String) -&gt; UIImage? {
          let fileURL = documentsUrl.appendingPathComponent(fileName)
          print("Loading image from file: \(fileURL)")
          do {
              let imageData = try Data(contentsOf: fileURL)
              //let image = UIImage(data: imageData) // Bad - the image will appear twice as big as it should be, and very blurry!
              let image = UIImage(data: imageData, scale: UIScreen.main.scale) // Alamofire extension...important. Make sure that images we downloaded are recalled with the right scale for our device
              return image
          } catch {
              print("Error loading image : \(error)")
          }
          return nil
      }
  </code></pre>
  
  <p>If I download a 200x200 pixel image, iOS recognizes it as a 100x100 point image with a scale of 2.0 in the iPhone 7 simulator. If I save that image and recall it without setting the scale in the UIImage initializer extension provided by Alamofire, iOS will see it as a 200x200 point image with a scale of 1.0.</p>
  
  <p>Why does this occur? Is this the best practice for saving and loading images with the correct scale and resolution?</p>