I convert an image into .png data from a UIImageView
and print result on console with this code:
let img = img_view.image!.pngData()
print(img)
The result of this snippet is 232206 Bytes
Can I get only 232206
as integer output, without the "bytes" suffix?
That's the size (number of bytes) of the Data
, which you can access by .count
:
let sizeOfData = img.count // 232206
After all, Data
represents a collection of bytes, so it conforms to Collection
, which has the count
property.
Use count
property:
let imgData = imgView.image!.pngData() let imgBytesCount = imgData!.count print(imgBytesCount)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.