不确定我做错了什么,我想创建一个简单的自定义相机,我创建AVCapturePhotoOutput将其附加到AVCaptureSession,然后使用最少设置创建AVCapturePhotoSettings以使图片工作,请参阅下面的代码。 / p>
我得到异常kCVPixelBufferPixelFormatTypeKey没有定义,但确实在我传递的NSDictionary中。
我需要一些亮点,谢谢
public void TakePicture()
{
var output = new AVCapturePhotoOutput();
_captureSession.AddOutput(output);
var settings = AVCapturePhotoSettings.Create();
var previewPixelType = settings.AvailablePreviewPhotoPixelFormatTypes.First();
var keys = new[]
{
new NSString("kCVPixelBufferPixelFormatTypeKey"),
new NSString("kCVPixelBufferWidthKey"),
new NSString("kCVPixelBufferHeightKey"),
};
var objects = new NSObject[]
{
// don't have to be strings... can be any NSObject.
previewPixelType,
new NSString("160"),
new NSString("160")
};
var dicionary = new NSDictionary<NSString, NSObject>(keys, objects);
settings.PreviewPhotoFormat = dicionary;
output.CapturePhoto(settings,this);
}
答案 0 :(得分:0)
这是因为Xamarin中没有kCVPixelBufferPixelFormatTypeKey
。
我们应该在这里使用CVPixelBuffer.PixelFormatTypeKey 。编译时会自动转换为kCVPixelBufferPixelFormatTypeKey
。
与kCVPixelBufferWidthKey
和kCVPixelBufferHeightKey
相同的原因,api在Xamarin.iOS中为CVPixelBuffer.WidthKey
和CVPixelBuffer.HeightKey
。