2017-04-11 1 views
0

(captureImage)카메라으로 찍히고 크기가 조정되었습니다. 압축 후 이미지 크기를 늘리려면 UIImageJPEGRepresentation을 사용합니다. 정상적인 동작입니까, 아니면 잘못된 방식으로 압축/크기 조정을하고 있습니까?UIImageJPEG 표현이 UIImage 크기를 증가합니다.

if let image = captureImage { 
    print(image.size) // (700, 700) 
    let compressedImageData = UIImageJPEGRepresentation(image, 0.3)! 
    let compressedImage = UIImage(data: compressedImageData)! 
    print(compressedImage.size) // (3024, 3024) 
} 
+1

링크를 울부 짖는 소리를 참조하십시오 http://stackoverflow.com/questions/29137488/how-do-i-resize-the-uiimage-to-reduce-upload-image-size 도움이 될 수 있습니다. – Aashish1aug

+0

이미지 크기를 조정합니다. https://iosdevcenters.blogspot.com/2015/12/how-to-resize-image-in-swift-in-ios.html –

답변

0

예이 코드는 파일 크기를 가져 오는

let compressedImageData = UIImageJPEGRepresentation(image, 0.3)! 

한 가지 방법은 문서 디렉토리에 저장하여 이미지 압축된다. 예를 들어 -

let filePath = fileURL 
     var fileSize : UInt64 

     do { 
      //return [FileAttributeKey : Any] 
      let attr = try FileManager.default.attributesOfItem(atPath: filePath.path) 
      fileSize = attr[FileAttributeKey.size] as! UInt64 

      //if you convert to NSDictionary, you can get file size old way as well. 
      let dict = attr as NSDictionary 
      fileSize = dict.fileSize() 
      print(fileSize) 

     } catch { 
      print("Error: \(error)") 
     } 
관련 문제