2010-12-18 16 views
8

, biz iphone cihaz kamera kullanarak bazı perticular zaman aralıklarında programlı de fotoğraf alabilir miyim?Fotoğraf iPhone'da Programlı olarak nasıl çekilir? Cihaz kamera kullanarak nasıl kullanılır? iPhone App

Evetse, lütfen iPhone App'te programlı olarak nasıl fotoğraf çekebileceğimizi bana bildirin.

Lütfen Yardım ve Önerilerinizi gönderin.

sayesinde

+0

aynı soruyu. Ben her zaman bunu yapmak yeteneğine sahip bazı fotoğrafçılık uygulamaları ile ilgilenen .. –

cevap

8

UIImagePickerController programlı denebilecek bir takePicture yöntemi vardır.

+0

takePicture mathod arayarak iphone cihaz kamera kullanarak yeni hareketsiz görüntüler alabilir miyim veya ben sadece resim kütüphanesine erişebilir ve bu resmi – ios

+0

@ Prerak'tan yakalayabilirim , takePicture'ın "cihaz kamerasını kullanarak yeni fotoğraflar çekmesi" için kullanılması amaçlanmıştır. Sadece resim kitaplığını alıyorsanız, UIImagePickerController kaynağınızın sourceType özelliğini UIImagePickerControllerSourceTypeCamera olarak ayarladığınızdan emin olun. Bu size kamera arayüzünü verecektir. –

+0

@Prerak: Sanırım yapabilirsin, iPhone'umda TimerCamera adlı ücretsiz bir uygulama kullanıyorum ve sürekli fotoğraf çekebiliyorum. –

0

UIImagePickerController'ı kullanarak resim çekmek için bir TakePicture yöntemi vardır.

Resim üzerinde daha fazla kontrol için, görüntüleri yakalamak için avcapturestillimageoutput yöntemini içeren AVFoundation üstbilgisini kullanabilirsiniz. More Info

0

ithalat .h bu dosya: .m içinde

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

koymak: Burada

- (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; 
} 
İlgili konular