funcionando
This commit is contained in:
parent
abcea1610d
commit
865c7ecc86
|
@ -10,6 +10,10 @@ using System.IO;
|
||||||
using ZXing.Common; // Para DecodingOptions y otros
|
using ZXing.Common; // Para DecodingOptions y otros
|
||||||
using ZXing.Windows.Compatibility;
|
using ZXing.Windows.Compatibility;
|
||||||
using BarcodeReader = ZXing.OpenCV.BarcodeReader; // Asegúrate de añadir este using
|
using BarcodeReader = ZXing.OpenCV.BarcodeReader; // Asegúrate de añadir este using
|
||||||
|
using System.Media;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using Brushes = System.Windows.Media.Brushes;
|
||||||
|
|
||||||
|
|
||||||
namespace QRReaderFromAndroid
|
namespace QRReaderFromAndroid
|
||||||
{
|
{
|
||||||
|
@ -22,6 +26,8 @@ namespace QRReaderFromAndroid
|
||||||
private BarcodeReader _reader;
|
private BarcodeReader _reader;
|
||||||
private HashSet<string> _scannedBarcodes = new HashSet<string>();
|
private HashSet<string> _scannedBarcodes = new HashSet<string>();
|
||||||
private const string FilePath = "scanned_barcodes.txt";
|
private const string FilePath = "scanned_barcodes.txt";
|
||||||
|
private SoundPlayer _soundPlayer = new SoundPlayer("D:\\Proyectos\\VisualStudio\\QRReaderFromAndroid\\store-scanner-beep-90395.wav"); // Configura la ruta al archivo de sonido
|
||||||
|
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
@ -61,21 +67,46 @@ namespace QRReaderFromAndroid
|
||||||
{
|
{
|
||||||
var bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(frame);
|
var bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(frame);
|
||||||
var result = ScanBarcode(bitmap);
|
var result = ScanBarcode(bitmap);
|
||||||
if (result != null && result.Text.Length == 13 && _scannedBarcodes.Add(result.Text))
|
if (result != null && result.Text.Length == 13)
|
||||||
{
|
{
|
||||||
// Actualizar UI de forma segura
|
// Actualizar UI de forma segura
|
||||||
|
barcodeText.Text = $"Scanned: {result.Text}";
|
||||||
Dispatcher.Invoke(() =>
|
Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
barcodeList.Items.Add(result.Text);
|
if (!_scannedBarcodes.Contains(result.Text))
|
||||||
barcodeText.Text = $"Scanned: {result.Text}";
|
{
|
||||||
});
|
_scannedBarcodes.Add(result.Text);
|
||||||
|
AddBarcodeToList(result.Text);
|
||||||
SaveBarcode(result.Text);
|
SaveBarcode(result.Text);
|
||||||
|
_soundPlayer.Play();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectBarcodeInList(result.Text);
|
||||||
|
//_soundPlayer.Play();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
cameraImage.Source = BitmapToImageSource(bitmap);
|
cameraImage.Source = BitmapToImageSource(bitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddBarcodeToList(string barcode)
|
||||||
|
{
|
||||||
|
barcodeList.Items.Add(barcode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectBarcodeInList(string barcode)
|
||||||
|
{
|
||||||
|
int index = barcodeList.Items.IndexOf(barcode);
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
barcodeList.SelectedIndex = index;
|
||||||
|
barcodeList.ScrollIntoView(barcodeList.SelectedItem); // Asegura que el ítem seleccionado sea visible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadScannedBarcodes()
|
private void LoadScannedBarcodes()
|
||||||
{
|
{
|
||||||
if (File.Exists(FilePath))
|
if (File.Exists(FilePath))
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue