पर कैमरे के साथ ली गई तस्वीरों में वास्तव में अंधेरा आ गया है कैमरा पूर्वावलोकन सही दिखता है, लेकिन जब मैं एक तस्वीर लेता हूं और इसे कैमरा रोल में सहेजता हूं तो तस्वीर बहुत अंधेरा हो जाती है। यहाँ धागे का एक गुच्छा कोशिश की लेकिन कुछ भी हल नहीं किया। मेरा कोड यहाँ है।आईओएस डब्ल्यू/स्विफ्ट
यह कैमरा/पूर्वावलोकन सेट और ठीक काम करता है:
captureSession.sessionPreset = AVCaptureSessionPreset640x480
let devices = AVCaptureDevice.devices()
// Loop through all the capture devices on this phone
for device in devices {
// Make sure this particular device supports video
if (device.hasMediaType(AVMediaTypeVideo)) {
// Finally check the position and confirm we've got the back camera
if(device.position == AVCaptureDevicePosition.Back) {
captureDevice = device as? AVCaptureDevice
}
}
}
if captureDevice != nil {
beginSession()
}
func beginSession() {
var err : NSError? = nil
if captureSession.canAddInput(AVCaptureDeviceInput(device: captureDevice, error: &err)) {
captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &err))
if err != nil {
println("error: \(err?.localizedDescription)")
}
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
self.view.layer.addSublayer(previewLayer)
self.view.bringSubviewToFront(cameraButton)
previewLayer?.frame = self.view.layer.frame
// start camera
captureSession.startRunning()
}
यह कहा जाता है जब चित्र लिया जाता है:
@IBAction func photoTaken(sender: UIButton) {
stillImageOutput.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
if captureSession.canAddOutput(stillImageOutput) {
captureSession.addOutput(stillImageOutput)
}
var videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo)
if videoConnection != nil {
// Show next step button
self.view.bringSubviewToFront(self.nextStep)
self.nextStep.hidden = false
// Secure image
stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection) {
(imageDataSampleBuffer, error) -> Void in
var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
self.image = UIImage(data: imageData)
}
// Freeze camera preview
captureSession.stopRunning()
}
}
इस के बाद चित्र लिया जाता है कहा जाता है जब उपयोगकर्ता हिट बटन आगे बढ़ने के लिए (यह छवि को अब कैमरे के रोल में सहेजता है, लेकिन जब मैं छवियों को अच्छे लगने के लिए अंततः अधिक करता हूं):
@IBAction func nextStepTapped(sender: UIButton) {
// Save to camera roll & proceeed
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil)
}
मेरा अनुमान है कि यह मुद्दा photoTaken() फ़ंक्शन के भीतर है, लेकिन मुझे कोई जानकारी नहीं है। यह स्विफ्ट/एक्सकोड में एक ऐप लिखने वाला मेरा पहला समय है, इसलिए किसी भी मदद की सराहना की जाएगी। दोबारा, मुद्दा यह है कि सहेजी गई तस्वीर बेहद अंधेरा है और मैंने इस समस्या से संबंधित इंटरनेट पर जो कुछ भी पा सकता है, उससे काफी कुछ करने की कोशिश की है, लेकिन कुछ भी काम नहीं करता है। धन्यवाद!
संपादित करें: यह ध्यान देने योग्य हो सकता है कि मैं इसे एक आईफोन 4 एस पर परीक्षण कर रहा हूं। क्या इसका इसके साथ कुछ लेना चाहिए?
क्या आप जानते हैं कि कोई और समाधान है या नहीं? कल्पना कीजिए कि मैं एक कैमरा ऐप बना रहा हूं जो शटर बटन दबाए बिना, इसे लॉन्च होने के तुरंत बाद एक फोटो लेता है। मैं सत्र में आउटपुट कैसे जोड़ूं और बिना किसी अंधेरे के जितनी जल्दी हो सके फोटो ले सकता हूं? बीटीडब्ल्यू, मैं नए फोटो आउटपुट का उपयोग कर रहा हूं, पुराने अभी भी छवि आउटपुट नहीं। –
यह मेरे लिए काम किया! –
यह अंधेरे वीडियो शुरू करने की समस्या के लिए भी काम करता है। – scaryguy