以下のようなCameraViewクラスを作成し、sessionから画像を取得するプログラムを作成しました。
sessionから取得した画像をCameraViewクラスのメンバ変数 UIImage imageに格納し、ViewControllerクラス内のUIImageViewにimageを貼り付けることで動的にUIImageViewにカメラの画像を表示させようとしています。
sessionの処理が行われる度にViewControllerの描画の更新を行うにはどのような処理にする必要があるでしょうか?
ご存知の方がいらっしゃいましたら御回答をお願いいたします。
public CameraView{
bool SetupCaptureSession()
{
// configure the capture session for low resolution, change this if your code
// can cope with more data or volume
session = new AVCaptureSession
{
SessionPreset = AVCaptureSession.PresetMedium
};
// ここで使用するデバイスの設定をしている // create a device input and attach it to the session var captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video); if (captureDevice == null) { Console.WriteLine("No captureDevice - this won't work on the simulator, try a physical device"); return false; } // ここでカメラの設定を変更をかけるためにロックをかけている //Configure for 15 FPS. Note use of LockForConigfuration()/UnlockForConfiguration() NSError error = null; captureDevice.LockForConfiguration(out error); if (error != null) { Console.WriteLine(error); captureDevice.UnlockForConfiguration(); return false; } if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) captureDevice.ActiveVideoMinFrameDuration = new CMTime(1, 15); // ここで設定変更終了し、ロックを解除している captureDevice.UnlockForConfiguration(); var input = AVCaptureDeviceInput.FromDevice(captureDevice); if (input == null) { Console.WriteLine("No input - this won't work on the simulator, try a physical device"); return false; } session.AddInput(input); // create a VideoDataOutput and add it to the sesion var settings = new CVPixelBufferAttributes { PixelFormatType = CVPixelFormatType.CV32BGRA }; using (var output = new AVCaptureVideoDataOutput { WeakVideoSettings = settings.Dictionary }) { queue = new DispatchQueue("myQueue"); outputRecorder = new OutputRecorder(); // サブスレッド用のシリアルキューを用意し、そこでフレームの取得を行う output.SetSampleBufferDelegate(outputRecorder, queue); session.AddOutput(output); } session.StartRunning(); // セッションが動きだし、実際にデータを取得する return true; } }
回答1件
あなたの回答
tips
プレビュー