我正在学习一些基本的图像处理并使用灰度BMP文件来处理某些算法,但我想将我的代码转换成彩色BMP文件而不是灰度。我正在使用EasyBMP库并具有以下内容来读入和写入我的BMP文件:
func generateHMAC(key: String, data: String) -> String {
var result: [CUnsignedChar]
if let cKey = key.cStringUsingEncoding(NSUTF8StringEncoding),
cData = data.cStringUsingEncoding(NSUTF8StringEncoding)
{
let algo = CCHmacAlgorithm(kCCHmacAlgSHA512)
result = Array(count: Int(CC_SHA512_DIGEST_LENGTH), repeatedValue: 0)
CCHmac(algo, cKey, cKey.count-1, cData, cData.count-1, &result)
}
else {
// as @MartinR points out, this is in theory impossible
// but personally, I prefer doing this to using `!`
fatalError("Nil returned when processing input strings as UTF8")
}
let hash = NSMutableString()
for val in result {
hash.appendFormat("%02hhx", val)
}
return hash as String
}
我尝试使用哪种步骤使我的程序与RGB图像兼容?