Skip to content

Geeksltd/Zebble.BarcodeScanner

Repository files navigation

Zebble.BarcodeScanner

logo

Zebble.BarcodeScanner is a Zebble plugin based on the open source Barcode Library: ZXing (Zebra Crossing).

NuGet


Setup


Api Usage

You can scan all 1D barcodes as simple as:

var result = await new BarcodeScanner().Scan();
await Alert.Show(result.Text);

Also, when you need a custome layout for your scan page.

async Task Scan()
{
	var bs = new BarcodeScanner();
	bs.ScanningOlerlay = await GetOverlay();
	var result = await bs.Scan();
	await Alert.Show(result.Text);
}

async Task<View> GetOverlay()
{
	var result = new Stack(RepeatDirection.Vertical);

	result.Width.BindTo(Root.Width);
	result.Height.BindTo(Root.Height);

	var canvasTop = GetCanvas();
	var canvasBottom = GetCanvas();

	canvasTop.Width.BindTo(Root.Width);
	canvasBottom.Width.BindTo(Root.Width);

	SetHeight(canvasTop, 0.3F);
	SetHeight(canvasBottom, 0.3F);

	var middleStack = new Stack(RepeatDirection.Horizontal);

	var canvasLeft = GetCanvas();
	var canvasRight = GetCanvas();
	var canvasCenter = new Canvas();

	canvasCenter.Border(all: 2, color: Colors.LawnGreen);

	canvasLeft.Width.BindTo(Root.Width, Root.Height, (w, h) => (w - (h * 0.4F)) / 2);
	canvasRight.Width.BindTo(Root.Width, Root.Height, (w, h) => (w - (h * 0.4F)) / 2);
	canvasCenter.Width.BindTo(Root.Height, h => h * 0.4F);

	SetHeight(canvasLeft, 0.4F);
	SetHeight(canvasRight, 0.4F);
	SetHeight(canvasCenter, 0.4F);
	SetHeight(middleStack, 0.4F);

	await middleStack.Add(canvasLeft);
	await middleStack.Add(canvasCenter);
	await middleStack.Add(canvasRight);

	await result.Add(canvasTop);
	await result.Add(middleStack);
	await result.Add(canvasBottom);

	return result;
}

Canvas GetCanvas() => new Canvas { BackgroundColor = Colors.Black, Opacity = 0.25F };
void SetHeight(View view, float scale) => view.Height.BindTo(Root.Height, h => h * scale);

Properties

Property Type Android iOS Windows
PossibleFormats PossibleFormats x x x
ScanningOlerlay Zebble.View x x x

Methods

Method Return Type Parameters Android iOS Windows
Scan Task<BarcodeResult> bool => useCamera = true,
OnError => errorAction = OnError.Alert
x x x

About

Barcode Scanner Plugin for Zebble for Xamarin

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages