Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay captured Jpeg File
    text
    copied!<p>I'm able to save the captured image from a barcode scanner using this code:</p> <pre><code> Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.DefaultExt = ".jpg"; dlg.Filter = "JPEG Images (.jpg)|*.jpg|All files (*.*)|*.*"; if (dlg.ShowDialog() == true) { using (FileStream file = File.OpenWrite(dlg.FileName)) { file.Write(e.ImageBuffer, 0, e.ImageSize); } } </code></pre> <p>However, I would like to display the captured image using WPF but I get a distorted image.</p> <pre><code>private void _barcodeScannerInstance_SavePhotoEvent(object sender, ImageEventArgs e) { SetBitmap(e.ImageBuffer, 350, 263, 96); } private void SetBitmap(byte[] image, int width, int height, int dpi) { MainWindow.Instance.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate() { BitmapSource bitmapSource = BitmapSource.Create( width, height, (double)dpi, (double)dpi, PixelFormats.Bgr24, null, image, ((width * 24 + 31) &amp; ~31) &gt;&gt; 3); HwModeScreen.BarcodeImageCanvas.Children.Clear(); Image myImage = new Image(); myImage.Width = HwModeScreen.BarcodeImageCanvas.ActualWidth; myImage.Height = HwModeScreen.BarcodeImageCanvas.ActualHeight; myImage.Stretch = Stretch.Fill; myImage.Source = bitmapSource; HwModeScreen.BarcodeImageCanvas.Children.Add(myImage); }); </code></pre> <p>Here is the image I see. It should be a black and white picture of a kleenex box.</p> <p><img src="https://img.photobucket.com/albums/v85/Keyoh/distortedphoto.jpg" alt="alt text"></p> <p>Here is the saved jpg file: <img src="https://img.photobucket.com/albums/v85/Keyoh/barcodephoto2.jpg" alt="alt text"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload