import UIKit
import Metal
import MetalKit
class CIImageView: MTKView{
private var ciContext: CIContext?
var image: CIImage?{
didSet{
setNeedsDisplay()
}
}
override init(frame frameRect: CGRect, device: MTLDevice?) {
super.init(frame: frameRect, device: device)
ciContext = CIContext(mtlDevice: self.device!, options: [CIContextOption.workingColorSpace: NSNull()])
self.isPaused = true
self.enableSetNeedsDisplay = true
}
required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func draw(_ rect: CGRect) {
super.draw(rect)
guard let image = image else { return }
guard let commandBuffer = self.device?.makeCommandQueue()?.makeCommandBuffer() else { return }
guard let drawingTexture = self.currentDrawable?.texture else { return }
guard let currentDrawable = self.currentDrawable else { return }
self.drawableSize = image.extent.size
ciContext?.render(image, to: drawingTexture, commandBuffer: commandBuffer, bounds: CGRect(x: 0, y: 0, width: image.extent.width, height: image.extent.height), colorSpace: CGColorSpaceCreateDeviceRGB())
commandBuffer.present(currentDrawable)
commandBuffer.commit()
MYLog(message: self.frame)
MYLog(message: self.drawableSize)
}
}
MTKView显示CIImage
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- option配置项(测试用) 设置高亮 注意点:在legend中设置selectedMode:false,否则会有...
- html中img标签图片怎么才能设置它的显示高度 ,其余部分不显示,而不是压缩它的整体高度,让它全部显示
- 系统: macOS_10.12 导致文件破损原因: 解决问题办法: “通用”里有时没有“任何来源”这个选项解决办法...
- 在ios中,每一个UIImageView都有他的frame大小,但是如果图片的大小和这个frame的大小不符合的时...