- True Color Image PNG
- 24bit PNG Support
- Compression Support
- Stream write Support
import opencv2
...
let fileUrl: URL = FileManager.default.temporaryDirectory.appendingPathComponent("test.png")
do {
try FileManager.default.removeItem(atPath: fileUrl.path)
} catch {
print(error.localizedDescription)
}
let frameCount = 3
let width = 100
let height = 100
let apng = AnimationPngEncoder(fileUrl: fileUrl, width: width, height: height,
frameCount: frameCount, fps: 10, compression: 3)
do {
for p in 0..<frameCount {
try autoreleasepool {
let img = Mat(size: Size(width: Int32(height), height: Int32(width)),
type: CvType.CV_8UC3, scalar: Scalar(0,0,0))
Imgproc.circle(img: img, center: Point2i(x: Int32(p * 10), y: 50), radius: 5, color: Scalar(255,0,0), thickness: -1)
Imgproc.circle(img: img, center: Point2i(x: 50, y: Int32(p * 10)), radius: 5, color: Scalar(0,0,255), thickness: -1)
Imgproc.cvtColor(src: img, dst: img, code: ColorConversionCodes.COLOR_BGR2RGB)
try apng.push(img: img)
}
}
try apng.close()
} catch {
print("error:", error)
}
print(fileUrl)