1
Vote

Any how Zxing Small size of bar code Image not Scanning

description

Hi,

i'm using Zxing library to bar code scanning it's working good for Large scale image but when i'm trying to scan small size of image it's not working and not scanning any thing from web cam...
public sealed partial class BarcodeScanPage : Page
{

    private readonly MediaCapture _mediaCapture = new MediaCapture();
    private Result _result;

    public BarcodeScanPage()
    {
        this.InitializeComponent();
    }

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        try
        {
            var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            var device = (from webcam in cameras where webcam.EnclosureLocation != null && webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back select webcam).FirstOrDefault();

            MediaCaptureInitializationSettings settings;
            settings = new MediaCaptureInitializationSettings { VideoDeviceId = device.Id };

            await _mediaCapture.InitializeAsync(settings);
            //SetResolution();
            if (DisplayInformation.AutoRotationPreferences == DisplayOrientations.Portrait)
            {
                SimpleOrientationSensor sensor = SimpleOrientationSensor.GetDefault();
                sensor.OrientationChanged += (s, arg) =>
                {
                    switch (arg.Orientation)
                    {
                        case SimpleOrientation.Rotated90DegreesCounterclockwise:
                            _mediaCapture.SetPreviewRotation(VideoRotation.None);
                            break;
                        case SimpleOrientation.Rotated180DegreesCounterclockwise:
                        case SimpleOrientation.Rotated270DegreesCounterclockwise:
                            _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise180Degrees);
                            break;
                        default:
                            _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
                            break;
                    }
                };
            }

            VideoCapture.Source = _mediaCapture;
            await _mediaCapture.StartPreviewAsync();

            while (_result == null)
            {
                var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("scan.jpg", CreationCollisionOption.GenerateUniqueName);
                await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);
                var stream = await photoStorageFile.OpenReadAsync();
                var writeableBmp = new WriteableBitmap(1, 1);
                writeableBmp.SetSource(stream);
                writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
                stream.Seek(0);
                writeableBmp.SetSource(stream);
                _result = ScanBitmap(writeableBmp);
                await photoStorageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }
            await _mediaCapture.StopPreviewAsync();
            VideoCapture.Visibility = Visibility.Collapsed;
            CaptureImage.Visibility = Visibility.Visible;
            Cache.ScannedVINNumber = _result.Text;
            Frame.Navigate(typeof(Grounding));

        }
        catch
        {

        }

    }


    private Result ScanBitmap(WriteableBitmap writeableBmp)
    {

        var barcodeReader = new BarcodeReader
        {
            TryHarder = true,
            AutoRotate = true
        };
        var result = barcodeReader.Decode(writeableBmp);

        if (result != null)
        {
            CaptureImage.Source = writeableBmp;
        }

        return result;
    }

    public async void SetResolution()
    {
        System.Collections.Generic.IReadOnlyList<IMediaEncodingProperties> res;
        res = this._mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
        uint maxResolution = 0;
        int indexMaxResolution = 0;

        if (res.Count >= 1)
        {
            for (int i = 0; i < res.Count; i++)
            {
                var vp = (VideoEncodingProperties)res[i];
                if (vp.Width > maxResolution)
                {
                    indexMaxResolution = i;
                    maxResolution = vp.Width;

                }
            }
            await this._mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, res[res.Count - 1]);
        }
    }

    protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e)
    {

        try
        {
            await _mediaCapture.StopPreviewAsync();
        }
        catch
        {


        }

    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Frame.GoBack();
    }
}
}

Please help me any one and suggest me to any paid other library

comments