Convert UIimage (take a picture) to NSData

后端 未结 1 1970
攒了一身酷
攒了一身酷 2021-01-19 18:45

I used this method to take a picture.

func convertImageFromCMSampleBufferRef(sampleBuffer:CMSampleBuffer) -> CIImage{
    let pixelBuffer:CVPixelBufferRef         


        
相关标签:
1条回答
  • 2021-01-19 18:48

    You must convert CIImage to a CGImage, then CGImage to an UIImage, and then UIImage to NSData.

    static let context = CIContext(options:nil);
    let tempImage:CGImageRef = context.createCGImage(ciImage, fromRect: ciImage.extent())
    let image = UIImage(CGImage: tempImage);
    let imageData: NSData? = UIImageJPEGRepresentation(image, 0.6);
    
    0 讨论(0)
提交回复
热议问题