This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| uiLabel.text = "\u{00a0} Hello World \u{200c}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PIL import Image | |
| img = Image.open("cat.jpg") | |
| # 图片尺寸 | |
| print(img.size) | |
| img.size[0] # 宽度 | |
| img.size[1] # 高度 | |
| # 操作像素 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private func createTexture(sampleBuffer: CMSampleBuffer, planeIndex: Int, pixelFormat: MTLPixelFormat) throws -> MTLTexture { | |
| guard let cvImageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { | |
| throw MyError.normal | |
| } | |
| let isPlanar = CVPixelBufferIsPlanar(cvImageBuffer) | |
| let width = isPlanar ? CVPixelBufferGetWidthOfPlane(cvImageBuffer, planeIndex) : CVPixelBufferGetWidth(cvImageBuffer) | |
| let height = isPlanar ? CVPixelBufferGetHeightOfPlane(cvImageBuffer, planeIndex) : CVPixelBufferGetHeight(cvImageBuffer) | |
| var cvMetalTexture: CVMetalTexture? | |
| CVMetalTextureCacheCreateTextureFromImage(nil, _textureCache!, cvImageBuffer, nil, pixelFormat, width, height, planeIndex, &cvMetalTexture) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sampleBuffer: CMSampleBuffer | |
| guard let formatDesc = CMSampleBufferGetFormatDescription(sampleBuffer) else { return } | |
| let dimension = CMVideoFormatDescriptionGetDimensions(formatDesc) | |
| var ciImage = CIImage(cvImageBuffer: cvImageBuffer, options: nil) | |
| // 负数是顺时针旋转 | |
| ciImage = ciImage.transformed(by: CGAffineTransform(rotationAngle: -1 * CGFloat.pi / 2)) |