[英]Can I convert .png data into an Int in Swift?
I convert an image into .png data from a UIImageView
and print result on console with this code: 我将图像从
UIImageView
转换为.png数据,并使用以下代码在控制台上打印结果:
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? 此代码段的结果是
232206 Bytes
。我能否仅获得232206
作为整数输出,而没有“ bytes”后缀?
That's the size (number of bytes) of the Data
, which you can access by .count
: 这就是大小(字节数)
Data
,您可以通过访问.count
:
let sizeOfData = img.count // 232206
After all, Data
represents a collection of bytes, so it conforms to Collection
, which has the count
property. 毕竟,
Data
表示字节的集合,因此它符合具有count
属性的Collection
。
Use count
property: 使用
count
属性:
let imgData = imgView.image!.pngData() let imgBytesCount = imgData!.count print(imgBytesCount)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.