.NET MAUI Gallery scan
The SDK allows you to decode barcodes from image files. It supports several image formats, including BMP, PNG, and JPG.
The method below picks a picture with MediaPicker (part of .NET MAUI, no other package; on Android 13 and later it opens the system photo picker) and sends it to ScanImage as base64. Put it in your page's class, the MainPage of the General example (its DidFinishScanning gets the results), and call it from a button, for example <Button Text="Scan from gallery" Clicked="scanFromGallery" /> in MainPage.xaml:
private async void scanFromGallery(object sender, EventArgs e)
{
// Pick an image from the gallery (MediaPicker is part of .NET MAUI)
FileResult? photo = await MediaPicker.Default.PickPhotoAsync();
if (photo == null)
return; // User canceled
using (var stream = await photo.OpenReadAsync())
using (var memoryStream = new MemoryStream())
{
await stream.CopyToAsync(memoryStream);
byte[] imageBytes = memoryStream.ToArray();
string base64String = Convert.ToBase64String(imageBytes);
BKDView.ScanImage(base64String, this);
}
}