Witajcie,
Kiepski ze mnie programista, żeby nie powiedzieć ze żaden wiec proszę Was o pomoc.
Mam program który rozpoznaje kody kreskowe, korzysta z biblioteki ZXing. Wszystko działa jak należy, jednakże potrzebuje dodać funkcję rozpoznawania kodów. W tym celu doszedlem do "linq to xml" gdyż pamięć izolowana i localdb w WP 8.1 wydała mi się zbyt skomplikowana.
void cam_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
//skanowanie
//outputImg.Source = img;
BitmapImage img = new BitmapImage();
img.SetSource(e.ImageStream);
WriteableBitmap barcodeBitmap = new WriteableBitmap(img);
// create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
// detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);
XElement xelement = XElement.Load("produkty.xml");
//IEnumerable<XElement> produkty = xelement.Elements();
var prod = from p in xelement.Descendants("PRODUKT")
where p.Element("ID").Value == result.Text
select p.Element("NAZWA").Value;
foreach (var p in prod)
if (result != null)
{
MessageBox.Show(string.Format("Format: {0} {1} Content: {2} {3} Product: {4}", result.BarcodeFormat.ToString(), System.Environment.NewLine, result.Text, System.Environment.NewLine, p ));
}
timer.Change(1000, 1000);
});
}
W tym momencie powyższy kod nie wywala błędów ale także uniemożliwia pierwotne działanie aplikacji.
Zauważyłem także ze wywala mi wyjątek (zamieszczam w załączniku).
Wydaje mi się, że to on uniemożliwia mi w tym momencie wyświetlanie tych produktów.
Dodaje także mojego xml'a, jest to prosty składniowo plik, wstępnie nie będzie zawierał dużo danych.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Edited by XMLSpy -->
<PRODUKTY>
<PRODUKT>
<ID>9788372292704</ID>
<NAZWA>Ksiazka</NAZWA>
</PRODUKT>
<PRODUKT>
<ID>13124123</ID>
<NAZWA>Bob Dylan</NAZWA>
</PRODUKT>
<PRODUKT>
<ID>2096000099067</ID>
<NAZWA>Kod kreskowy</NAZWA>
</PRODUKT>
</PRODUKTY>