Scanner preview is strechted and I want to know if there's a workaround for that.
I'm using that to get the best resolution:
var options = new MobileBarcodeScanningOptions()
{
//TryHarder = true, //Gets or sets a flag which cause a deeper look into the bitmap.
AutoRotate = false,
UseFrontCameraIfAvailable = false,
InitialDelayBeforeAnalyzingFrames = 100,
CameraResolutionSelector = SelectLowestResolutionMatchingDisplayAspectRatio,
}
private CameraResolution SelectLowestResolutionMatchingDisplayAspectRatio(List<CameraResolution> availableResolutions)
{
var displayOrientationHeight = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ?
DeviceDisplay.MainDisplayInfo.Height : DeviceDisplay.MainDisplayInfo.Width;
var displayOrientationWidth = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ?
DeviceDisplay.MainDisplayInfo.Width : DeviceDisplay.MainDisplayInfo.Height;
var targetRatio = displayOrientationHeight / displayOrientationWidth;
var targetHeight = displayOrientationHeight;
//camera API lists all available resolutions from highest to lowest, perfect for us
//making use of this sorting, following code runs some comparisons to select the lowest resolution that matches the
screen aspect ratio and lies within tolerance
//selecting the lowest makes Qr detection actual faster most of the time
var bestResolutions = from r in availableResolutions
let aspectRatio = (double)r.Width / r.Height
let aspectRatioDiff = Math.Abs(aspectRatio - targetRatio)
let heightDiff = Math.Abs(r.Height - targetHeight)
orderby aspectRatioDiff, heightDiff
select r;
return bestResolutions.FirstOrDefault();
}
And when I try to open on android simulator it just crash, though it returns a valid resolution. I got this message: System.ArgumentNullException: 'Value cannot be null.
Parameter name: handle'
When I try to open in my device, it works at first, and the image is not strechted, but when I get out of preview and get back, it just crash when I try to open the scanner a second time, even if I kill the app. Can someone help me?
Scanner preview is strechted and I want to know if there's a workaround for that.
I'm using that to get the best resolution:
And when I try to open on android simulator it just crash, though it returns a valid resolution. I got this message: System.ArgumentNullException: 'Value cannot be null. Parameter name: handle'
When I try to open in my device, it works at first, and the image is not strechted, but when I get out of preview and get back, it just crash when I try to open the scanner a second time, even if I kill the app. Can someone help me?