2010-12-18 9 views
8

iPhone App में, हम iphone डिवाइस कैमरा का उपयोग करके कुछ perticular समय अंतराल प्रोग्राम के रूप में पर चित्रों ले सकते हैं?डिवाइस कैमरे का उपयोग कर आईफोन ऐप में प्रोग्रामेटिक रूप से चित्र कैसे लें?

यदि हां तो कृपया मुझे बताएं कि हम आईफोन ऐप में प्रोग्रामेटिक रूप से चित्र कैसे ले सकते हैं?

कृपया सहायता और सुझाव दें।

धन्यवाद,

+0

वही सवाल यहाँ। मुझे कुछ फ़ोटोग्राफ़ी ऐप्स में हमेशा दिलचस्पी है जो इसे करने में सक्षम हैं .. –

उत्तर

8

UIImagePickerController एक takePicture विधि है कि प्रोग्राम के रूप में कहा जा सकता है है।

+0

ले जाकर चित्रण मैथोड मैं आईफोन डिवाइस कैमरे का उपयोग कर नई छवियां ले सकता हूं या मैं केवल – ios

+0

@Prerak से चित्र लाइब्रेरी और फ़ैच तस्वीर तक पहुंच सकता हूं , टेक पिक्चर का उपयोग "कैमरा कैमरे का उपयोग कर नई छवियों को अभी भी लेने" के लिए किया जाना है। अगर आपको केवल तस्वीर लाइब्रेरी मिल रही है, तो सुनिश्चित करें कि आपने UIImagePickerController की स्रोत टाइप टाइप को UIImagePickerControllerSourceTypeCamera पर सेट किया है। यह आपको कैमरा इंटरफ़ेस देगा। –

+0

@Prerak: मुझे लगता है कि आप इसे कर सकते हैं, मैं अपने आईफोन में टाइमर कैमरा नामक एक मुफ्त ऐप का उपयोग कर रहा हूं और यह लगातार तस्वीरें ले सकता है। –

0

आप UIImagePickerController का उपयोग कर सकते हैं चित्र लेने के लिए चित्रण विधि है।

तस्वीर पर अधिक नियंत्रण के लिए आप AVFoundation शीर्षलेख का उपयोग कर सकते हैं जिसमें छवियों को कैप्चर करने के लिए avcapturestillimageoutput विधि शामिल है। More Info

0

आयात ज में इस फ़ाइल:

AVFoundation/AVCaptureInput.h 
AVFoundation/AVCaptureDevice.h 
AVFoundation/AVCaptureOutput.h 
AVFoundation/AVMediaFormat.h  

मीटर में डाल:

- (AVCaptureDevice *)frontCamera 
{ 
    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; 
    for (AVCaptureDevice *device in devices) 
    { 
     if ([device position] == AVCaptureDevicePositionFront) 
     { 
      return device; 
     } 
    } 
    return nil; 
} 

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    CGImageRef cgImage = [self imageFromSampleBuffer:sampleBuffer]; 
    self.theImage = [UIImage imageWithCGImage: cgImage ]; 
    CGImageRelease(cgImage); 

    NSCalendar *sysCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; 
    NSDateFormatter *df = [[NSDateFormatter alloc]init]; 
    df.calendar = sysCalendar; 
    [df setDateFormat:@"dd_MM_yyyy hh:mm:ss"]; 
    StrCapture = [NSString stringWithFormat:@"%@.jpeg",[df stringFromDate:[NSDate date]]]; 
    NSLog(@"StrCapture : %@",StrCapture); 

    NSData *imageData = UIImageJPEGRepresentation(self.theImage,1); 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 

    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:StrCapture]; 
    [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; 

    NSLog(@"ImagePAth : %@",fullPath); 
} 

- (CGImageRef) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer 
{ 
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
    CVPixelBufferLockBaseAddress(imageBuffer,0); 
    uint8_t baseAddress = (uint8_t)CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0); 
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
    size_t width = CVPixelBufferGetWidth(imageBuffer); 
    size_t height = CVPixelBufferGetHeight(imageBuffer); 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 

    CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); 
    CGImageRef newImage = CGBitmapContextCreateImage(newContext); 
    CGContextRelease(newContext); 

    CGColorSpaceRelease(colorSpace); 
    CVPixelBufferUnlockBaseAddress(imageBuffer,0); 

    return newImage; 
} 
संबंधित मुद्दे