アプリのバッファに画像データを保存しようとしているので、それを使用できますが、CGContextDrawImage 行で EXC_BAD_ACCESS エラーが発生します。ここに私が使用しているコードがあります:
resizedImage.Array() // resizedImage - resized image of 280x140 pixels size
func Array() {
let dataBuffer = UnsafeMutablePointer<CUnsignedChar>.alloc(156800) //alloc(156800)
memset(dataBuffer, 0, 156800)
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.ByteOrder32Big.rawValue | CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(dataBuffer, 280, 140, 8, 156800, colorSpace, bitmapInfo.rawValue)
let imageRef = CGImageCreateWithImageInRect(CGImage, CGRectMake(0, 0, 280, 140))
let rectMake = CGRectMake(0, 0, 280, 140)
CGContextDrawImage(context, rectMake, imageRef)
return
}
Apple のドキュメントにある自動メモリ割り当てのようにバッファとバイトを null と 0 に設定しようとすると、アプリはクラッシュしませんが、次のエラーが発生します。
Sep 17 17:18:33 VideoTester[4846] <Error>: CGBitmapContextCreate: invalid data bytes/row: should be at least 1120 for 8 integer bits/component, 3 components, kCGImageAlphaPremultipliedLast.
Sep 17 17:18:33 VideoTester[4846] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
何かが足りないようですが、実際には理解できません。アドバイスが必要です。ありがとうございます!