UIImagePNGRepresentation 失去透明度
UIImagePNGRepresentation loses its transparency
我正在开发一个使用网络协议 UPnP 连接多个设备的应用程序。
除其他外,我可以交换图像,它们是存储在我的项目文件夹中的文件夹中的文件。
为了发送图像,我得到了预定义的方法。
if let imageRequested = UIImage(named:"logo.png"){
let fileType = "image/png"
let pngRepresentation = [UInt8](UIImagePNGRepresentation(imageRequested)!)
let fileSize = UInt32(pngRepresentation.count)
writeBegin!(aWriterData, fileSize, fileType)
aWriteResource!(aWriterData, pngRepresentation, fileSize)
aWriteEnd!(aWriterData)
}
但是,当透明时,接收器得到的图像是黑色背景。我知道这不是接收器问题,因为有一个 Android 版本发送相同的图像并且它们是透明接收的。
有什么想法吗?
UIImageJPEGRepresentation 会将生成的图像转换为不支持透明度的 JPEG。您确定使用的是 UIImagePNGRepresentation 而不是 UIImageJPEGRepresentation 吗?
如果您使用 UIImagePNGRepresentation - 很奇怪,它应该可以正常工作,您能提供更多详细信息吗?
我正在开发一个使用网络协议 UPnP 连接多个设备的应用程序。
除其他外,我可以交换图像,它们是存储在我的项目文件夹中的文件夹中的文件。
为了发送图像,我得到了预定义的方法。
if let imageRequested = UIImage(named:"logo.png"){
let fileType = "image/png"
let pngRepresentation = [UInt8](UIImagePNGRepresentation(imageRequested)!)
let fileSize = UInt32(pngRepresentation.count)
writeBegin!(aWriterData, fileSize, fileType)
aWriteResource!(aWriterData, pngRepresentation, fileSize)
aWriteEnd!(aWriterData)
}
但是,当透明时,接收器得到的图像是黑色背景。我知道这不是接收器问题,因为有一个 Android 版本发送相同的图像并且它们是透明接收的。
有什么想法吗?
UIImageJPEGRepresentation 会将生成的图像转换为不支持透明度的 JPEG。您确定使用的是 UIImagePNGRepresentation 而不是 UIImageJPEGRepresentation 吗?
如果您使用 UIImagePNGRepresentation - 很奇怪,它应该可以正常工作,您能提供更多详细信息吗?