我正在使用此代码模糊图像:
#python3
import hashlib
rawdata = "put your data here"
sha = hashlib.sha256(str(rawdata).encode("utf-8")).hexdigest() #For Sha256 hash
print(sha)
mdpass = hashlib.md5(str(sha).encode("utf-8")).hexdigest() #For MD5 hash
print(mdpass)
有时据说在行extension CGImage {
func blurEffect(_ boxSize: CGFloat) -> CGImage? {
let boxSize = boxSize - (boxSize.truncatingRemainder(dividingBy: 2)) + 1
let inProvider = self.dataProvider
let height = vImagePixelCount(self.height)
let width = vImagePixelCount(self.width)
let rowBytes = self.bytesPerRow
let inBitmapData = inProvider?.data // Crash reported for this line
let inData = UnsafeMutableRawPointer(mutating: CFDataGetBytePtr(inBitmapData))
var inBuffer = vImage_Buffer(data: inData, height: height, width: width, rowBytes: rowBytes)
let outData = malloc(self.bytesPerRow * self.height)
var outBuffer = vImage_Buffer(data: outData, height: height, width: width, rowBytes: rowBytes)
vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, nil, 0, 0, UInt32(boxSize), UInt32(boxSize), nil, vImage_Flags(kvImageEdgeExtend))
let colorSpace = CGColorSpaceCreateDeviceRGB()
let context = CGContext(data: outBuffer.data, width: Int(outBuffer.width), height: Int(outBuffer.height), bitsPerComponent: 8, bytesPerRow: outBuffer.rowBytes, space: colorSpace, bitmapInfo: self.bitmapInfo.rawValue)
let imageRef = context?.makeImage()
free(outData)
return imageRef
}
}
上发生了崩溃:
let inBitmapData = inProvider?.data
我的理解是图像数据太大,无法一次全部加载到内存中。如果正确的话,我该如何更改代码以处理更大的图像?