private static Android.Util.Size ToPixels(Size dpSize) { var(width, height) = dpSize; var widthPx = DimensionUtils.ConvertDpToPixel((float)width); var heightPx = DimensionUtils.ConvertDpToPixel((float)height); return(new Android.Util.Size(widthPx, heightPx)); }
public Surface CreateSurface(Size requestSize) { var requestPixelSize = ToPixels(requestSize); var bufferSize = GetBufferSize(requestPixelSize); Size = DimensionUtils.ToXamarinFormsSize(bufferSize); var pixelSize = new System.Drawing.Size { Width = bufferSize.Width, Height = bufferSize.Height }; PixelSize = pixelSize; ConfigureTransform(requestPixelSize.Width, requestPixelSize.Height); _imageReader = ImageReader.NewInstance(bufferSize.Width, bufferSize.Height, ImageFormatType.Yuv420888, 4); _imageAvailableListener = new ImageAvailableListener(); _imageAvailableListener.ImageAvailable += PreviewImageAvailable; _imageReader.SetOnImageAvailableListener(_imageAvailableListener, _backgroundHandler); return(_imageReader.Surface); }