-1

ユーザーからの入力なしで写真を撮るには、iOS カメラが必要です。どうすればこれを行うことができますか?これまでの私のコードは次のとおりです。

-(void)initCapture{
    AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] init];

    AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init];

    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                AVVideoCodecJPEG, AVVideoCodecKey,
                                nil];


    [newStillImageOutput setOutputSettings:outputSettings];


    AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];

    if ([newCaptureSession canAddInput:newVideoInput]) {
        [newCaptureSession addInput:newVideoInput];
    }
    if ([newCaptureSession canAddOutput:newStillImageOutput]) {
        [newCaptureSession addOutput:newStillImageOutput];
    }
    self.stillImageOutput = newStillImageOutput;
}

他に何を追加する必要があり、ここからどこに行けばよいですか? 動画は撮りたくありません。静止画を 1 枚だけ撮ります。また、後で画像を UIImage に変換するにはどうすればよいですか? ありがとう

4

1 に答える 1

0

このチュートリアルによると、これを行うことができるはずです:

NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation: newStillImageOutput];
UIImage *image = [[UIImage alloc] initWithData:imageData];

そして、あなたの UIImage オブジェクトがあります!

于 2014-03-15T20:39:47.640 に答える