Get size of a UIImage (bytes length) not height and width

后端 未结 10 2138
说谎
说谎 2020-11-28 09:00

I\'m trying to get the length of a UIImage. Not the width or height of the image, but the size of the data.

10条回答
  •  广开言路
    2020-11-28 09:39

    If needed in human readable form we can use ByteCountFormatter

    if let data = UIImageJPEGRepresentation(image, 1.0) {
       let fileSizeStr = ByteCountFormatter.string(fromByteCount: Int64(data.count), countStyle: ByteCountFormatter.CountStyle.memory)
       print(fileSizeStr)
    }
    

    Where Int64(data.count) is what you need in numeric format.

提交回复
热议问题