/// <summary> /// uses the BarcodeWriterGeneric implementation and the <see cref="WriteableBitmapRenderer"/> class for decoding /// </summary> /// <param name="writer"></param> /// <param name="content"></param> /// <returns></returns> public static WriteableBitmap WriteAsWriteableBitmap(this IBarcodeWriterGeneric writer, string content) { var bitmatrix = writer.Encode(content); var renderer = new WriteableBitmapRenderer(); return(renderer.Render(bitmatrix, writer.Format, content, writer.Options)); }
private void RenderCard() { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; if (App.IsMobile) { bcImage.Width = bounds.Width; bcImage.Height = bounds.Width * .5625; bcGrid.Height = bcImage.Height + 20; bcGrid.Width = bounds.Width; bcGrid.Margin = new Thickness(0, 70, 0, 0); bcNumber.Width = bounds.Width; } else { bcImage.Width = bounds.Width * .40; bcImage.Height = (bounds.Width * .40) * .5625; bcGrid.Height = bcImage.Height + 20; bcGrid.Width = (bounds.Width * .40); bcGrid.Margin = new Thickness(0, 70, 0, 0); bcNumber.Width = bounds.Width * .40; } bcNumber.Text = theCard.Number; bcNumber.TextAlignment = TextAlignment.Center; ZXing.MultiFormatWriter mfw = new ZXing.MultiFormatWriter(); try { ZXing.Common.BitMatrix bm = mfw.encode(theCard.Number, theCard.Format, (int)bcImage.Width, (int)bcImage.Height); ZXing.Mobile.WriteableBitmapRenderer w = new WriteableBitmapRenderer(); ZXing.Common.EncodingOptions eo = new ZXing.Common.EncodingOptions(); eo.Height = (int)bcImage.Height; eo.Width = (int)bcImage.Width; WriteableBitmap wbm = w.Render(bm, theCard.Format, theCard.Number, eo); bcImage.Source = wbm; } catch(Exception e) { CardEncodeErr.Text = e.Message; CardEncodeErr.Visibility = Visibility.Visible; } }
protected override BitmapSource Convert(BitMatrix value, Type targetType, object parameter, CultureInfo culture) { var output = value != null?Renderer.Render(value, ZXing.BarcodeFormat.QR_CODE, string.Empty, RenderSettings) : null; return(output); }
private void RenderCard() { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; if (App.IsMobile) { bcImage.Width = bounds.Width; if (theCard.Format == ZXing.BarcodeFormat.PDF_417) { bcImage.Height = bounds.Width * .35; bcNumber.Margin = new Thickness(0, 0, 0, 3); } else { bcImage.Height = bounds.Width * .4; bcNumber.Margin = new Thickness(0, 0, 0, 0); } bcGrid.VerticalAlignment = VerticalAlignment.Top; bcGrid.Height = bcImage.Height + 20; bcGrid.Width = bounds.Width; bcGrid.Margin = new Thickness(0, 70, 0, 0); bcNumber.Width = bounds.Width; } else { if (theCard.Format == ZXing.BarcodeFormat.PDF_417) { bcImage.Height = (bounds.Width * .40) * .3; } else { bcImage.Height = (bounds.Width * .40) * .5625; } bcImage.Width = bounds.Width * .40; bcImage.HorizontalAlignment = HorizontalAlignment.Center; bcImage.VerticalAlignment = VerticalAlignment.Center; bcGrid.Height = bcImage.Height + 20; bcGrid.Width = (bounds.Width * .40); bcGrid.Margin = new Thickness(0, 70, 0, 0); bcNumber.Width = bounds.Width * .40; if (bounds.Width > 800) bcNumber.FontSize = 20; else if (bounds.Width > 600 && Width <= 800) bcNumber.FontSize = 16; else if (bounds.Width <= 600) bcNumber.FontSize = 11; } bcNumber.Text = theCard.Number; bcNumber.TextAlignment = TextAlignment.Center; ZXing.MultiFormatWriter mfw = new ZXing.MultiFormatWriter(); try { var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; ZXing.Common.BitMatrix bm; if (App.IsMobile) bm = mfw.encode(theCard.Number, theCard.Format, (int)(bcImage.Width * (scaleFactor - 1)), (int)(bcImage.Height * (scaleFactor - 1))); else bm = mfw.encode(theCard.Number, theCard.Format, (int)bcImage.Width, (int)bcImage.Height); ZXing.Mobile.WriteableBitmapRenderer w = new WriteableBitmapRenderer(); ZXing.Common.EncodingOptions eo = new ZXing.Common.EncodingOptions(); eo.Height = (int)bcImage.Height; eo.Width = (int)bcImage.Width; WriteableBitmap wbm = w.Render(bm, theCard.Format, theCard.Number, eo); bcImage.Source = wbm; } catch(Exception e) { CardEncodeErr.Text = e.Message; CardEncodeErr.Visibility = Visibility.Visible; } }