Swift - 将图像保存为位图

时间:2015-04-24 17:50:55

标签: ios image swift bitmap byte

我正在尝试使用AVFoundation将图像保存为位图。现在我正在使用jpeg,并想知道我需要更改什么才能将图像保存为位图。附注 - 我们计划将byte []存储到我们的谷歌应用引擎上,然后任何需要该图像的设备(Android或IOS)将能够从数据库中提取byte []并将其转换为图像装置。这是一种有效的存储图像方式吗?如果不是你会建议什么?

这是我的代码将图像保存为jpeg

@IBAction func didPressTakePhoto(sender: AnyObject) {

    if let videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) {
        videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
        stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {(sampleBuffer, error) in
            if (sampleBuffer != nil) {
                var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
                var dataProvider = CGDataProviderCreateWithCFData(imageData)
                var cgImageRef = CGImageCreateWithJPEGDataProvider(dataProvider, nil, true, kCGRenderingIntentDefault)

                //change orientation based on if the camera is front or back

                if self.selectedCamera == 1 {
                    var image = UIImage(CGImage: cgImageRef, scale: 1.0, orientation: UIImageOrientation.LeftMirrored)
                    self.capturedImage.image = image
                } else {
                    var image = UIImage(CGImage: cgImageRef, scale: 1.0, orientation:UIImageOrientation.Right)
                    self.capturedImage.image = image
                }

0 个答案:

没有答案