我正在开发一个使用网络协议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 - 这很奇怪,它应该可以正常工作,你能提供更多细节吗?