मैं अपने ऐप में एक कस्टम कैमरा लागू करने के लिए AVFoundation कक्षाओं का उपयोग कर रहा हूं। मैं अभी भी छवियों को कैप्चर कर रहा हूं, वीडियो नहीं। मेरे पास सब कुछ काम कर रहा है लेकिन कुछ चीज से फंस गया है। जब भी एक छवि को कैप्चर किया जाता है और वीडियो कनेक्शन को उचित रूप से वीडियो सेट किया जाता है तो मैं डिवाइस अभिविन्यास को ध्यान में रखता हूं। एक कोड स्निपेट:AVCaptureVideoOrientation लैंडस्केप मोड का परिणाम अभी भी छवियों के ऊपर क्यों है?
// set the videoOrientation based on the device orientation to
// ensure the pic is right side up for all orientations
AVCaptureVideoOrientation videoOrientation;
switch ([UIDevice currentDevice].orientation) {
case UIDeviceOrientationLandscapeLeft:
// Not clear why but the landscape orientations are reversed
// if I use AVCaptureVideoOrientationLandscapeLeft here the pic ends up upside down
videoOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
case UIDeviceOrientationLandscapeRight:
// Not clear why but the landscape orientations are reversed
// if I use AVCaptureVideoOrientationLandscapeRight here the pic ends up upside down
videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
case UIDeviceOrientationPortraitUpsideDown:
videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
break;
default:
videoOrientation = AVCaptureVideoOrientationPortrait;
break;
}
videoConnection.videoOrientation = videoOrientation;
परिदृश्य मामलों में मेरी टिप्पणियां नोट करें। मुझे ओरिएंटेशन मैपिंग को उलटना है या परिणामी छवि उल्टा है। मैं निम्नलिखित कोड के साथ छवि को कैप्चर और सेव करता हूं:
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
self.stillImage = [UIImage imageWithData:imageData];
// notify observers (image gets saved to the camera roll)
[[NSNotificationCenter defaultCenter] postNotificationName:CaptureSessionManagerDidCaptureStillImageNotification object:self];
self.stillImage = nil;
}];
कोई अन्य छवि प्रसंस्करण या हेरफेर नहीं है।
मेरा ऐप उपरोक्त कोड के साथ काम करता है। मैं बस यह समझने की कोशिश कर रहा हूं कि अभिविन्यास स्थिरांक को परिदृश्य उन्मुखताओं के लिए क्यों उलट दिया जाना चाहिए। धन्यवाद!
नजर आता है UIDevice उन्मुखीकरण का उपयोग न करें जब आप वास्तव में उपयोग करना चाहते हैं UIInterface अभिविन्यास। – Till
आप इस मामले में 'UIInterface' अभिविन्यास का उपयोग नहीं कर सकते हैं। छवि को कैप्चर करने के समय डिवाइस अभिविन्यास हमेशा सही होता है। उस डेटा को कैप्चर करने के बाद 'stillImage' की छवि अभिविन्यास सही नहीं है। मैं UIDeviceOrientation का उपयोग करके इस मुद्दे को हल करने में सक्षम था और घूर्णन करते समय उचित UIImageOrientation में अनुवाद कर रहा था। उस समय, कोई भी यहाँ चिल्ला रहा था इसलिए मैंने कोड पोस्ट नहीं किया। यदि मेरे पास समय है तो मैं कोड जोड़ूंगा। – XJones
@XJones, कृपया अपने उत्तर को सही समाधान के साथ अपडेट करें। – Hemang