protected override void OnElementChanged(ElementChangedEventArgs <ZXingBarcodeImageView> e) { formsView = Element; if (imageView == null) { imageView = new ImageView(Xamarin.Forms.Forms.Context); base.SetNativeControl(imageView); } if (formsView != null && formsView.BarcodeValue != null) { var writer = new ZXing.Mobile.BarcodeWriter(); if (formsView != null && formsView.BarcodeOptions != null) { writer.Options = formsView.BarcodeOptions; } if (formsView != null && formsView.BarcodeFormat != null) { writer.Format = formsView.BarcodeFormat; } var value = formsView != null ? formsView.BarcodeValue : string.Empty; var image = writer.Write(value); imageView.SetImageBitmap(image); } base.OnElementChanged(e); }
void regenerate() { if (formsView != null && formsView.BarcodeValue != null) { var writer = new ZXing.Mobile.BarcodeWriter(); if (formsView != null && formsView.BarcodeOptions != null) { writer.Options = formsView.BarcodeOptions; } if (formsView != null && formsView.BarcodeFormat != null) { writer.Format = formsView.BarcodeFormat; } var value = formsView != null ? formsView.BarcodeValue : string.Empty; Device.BeginInvokeOnMainThread(() => { var image = writer.Write(value); imageView.Source = image; }); } }
private UIImage GetQRCode(string url) { var writer = new ZXing.Mobile.BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new ZXing.Common.EncodingOptions { Height = 250, Width = 250 } }; return(writer.Write(url)); }
public Stream ConvertImageStream(string text, int width = 500, int height = 500) { var barcodeWriter = new ZXing.Mobile.BarcodeWriter { Format = ZXing.BarcodeFormat.QR_CODE, Options = new ZXing.Common.EncodingOptions { Width = width, Height = height, Margin = 2 } }; barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer(); var bitmap = barcodeWriter.Write(text); var stream = new MemoryStream(); bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream); // this is the diff between iOS and Android stream.Position = 0; return(stream); }
void regenerate() { if (formsView != null && formsView.BarcodeValue != null) { var writer = new ZXing.Mobile.BarcodeWriter(); if (formsView != null && formsView.BarcodeOptions != null) { writer.Options = formsView.BarcodeOptions; } if (formsView != null && formsView.BarcodeFormat != null) { writer.Format = formsView.BarcodeFormat; } var value = formsView != null ? formsView.BarcodeValue : string.Empty; var image = writer.Write(value); imageView.SetImageBitmap(image); } }
public Bitmap GenerateQrImage(string content, int width, int height) { var writer = new ZXing.Mobile.BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new ZXing.Common.EncodingOptions { Height = height, Width = width, Margin = 0, PureBarcode = true, } }; writer.Renderer = new ZXing.Mobile.BitmapRenderer { Background = Color.Red, Foreground = Color.Black }; var bitmap = writer.Write(content); //var stream = new MemoryStream(); //bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream); // this is the diff between iOS and Android //stream.Position = 0; return(bitmap); }