コード例 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set view

            SetContentView(Resource.Layout.MyQR);

            // Generate QR code with details

            imageMyQR = FindViewById <ImageView>(Resource.Id.imageMyQR);

            var QRWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = 600,
                    Height = 600
                }
            };

            var MyQRCode = QRWriter.Write("Contact;2;Retail Store ltd");

            imageMyQR.SetImageBitmap(MyQRCode);
        }
コード例 #2
0
        public Stream ConvertImageStream(string text, int width = 300, int height = 300)
        {
            var xx = (float)UIScreen.MainScreen.Bounds.Width;
            int yy = 500;

            if (xx == 320.0)
            {
                yy = (int)(xx * 0.75);
            }

            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = yy,
                    Height = yy,
                    Margin = 1
                }
            };

            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();

            var bitmap = barcodeWriter.Write(text);
            var stream = bitmap.AsPNG().AsStream();             // this is the difference

            stream.Position = 0;

            return(stream);
        }
コード例 #3
0
        private 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)
                if (formsView != null)
                {
                    writer.Format = formsView.BarcodeFormat;
                }

                var value = formsView != null ? formsView.BarcodeValue : string.Empty;

                Device.BeginInvokeOnMainThread(() => {
                    var image = writer.Write(value);

                    imageView.SetImageBitmap(image);
                });
            }
        }
コード例 #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set view

            SetContentView(Resource.Layout.MyQR);

            // Generate QR code with details

            imageMyQR = FindViewById <ImageView>(Resource.Id.imageMyQR);

            var QRWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = 600,
                    Height = 600
                }
            };

            // QRType;ID;Name;Contact Type
            var MyQRCode = QRWriter.Write(myDetails.Type + ";" +
                                          myDetails.ID + ";" +
                                          myDetails.Name + ";" +
                                          myDetails.LastName + ";" +
                                          myDetails.defaultCurrency + ";" +
                                          myDetails.alternateCurrency + ";" +
                                          myDetails.DOB + ";" +
                                          myDetails.defaultLanguage
                                          );

            imageMyQR.SetImageBitmap(MyQRCode);
        }
コード例 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set view.
            SetContentView(Resource.Layout.Main);

            // Resources.
            imageBarcode = FindViewById <ImageView>(Resource.Id.qrImageView);

            // Create a QR code.
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions {
                    Width  = 300,
                    Height = 300
                }
            };

            // String to become QR code.
            var qrString = barcodeWriter.Write("Hello world!");

            // Assign QR code to ImageView.
            imageBarcode.SetImageBitmap(qrString);
        }
        void Regenerate()
        {
            if (!string.IsNullOrEmpty(formsView?.BarcodeValue))
            {
                var writer = new ZXing.Mobile.BarcodeWriter
                {
                    Renderer = new BitmapRenderer(formsView.QRColor)
                };

                if (formsView != null && formsView.BarcodeOptions != null)
                {
                    writer.Options = formsView.BarcodeOptions;
                }

                writer.Format = formsView.BarcodeFormat;

                var code = formsView.BarcodeValue;

                Device.BeginInvokeOnMainThread(() =>
                {
                    var image = writer.Write(code);
                    imageView.SetImageBitmap(image);
                });
            }
        }
コード例 #7
0
        public Task SalvarQrcode(string text, string filename, string description)
        {
            try
            {
                var barcodeWriter = new ZXing.Mobile.BarcodeWriter
                {
                    Format  = ZXing.BarcodeFormat.QR_CODE,
                    Options = new ZXing.Common.EncodingOptions
                    {
                        Width  = 1000,
                        Height = 1000,
                        Margin = 5
                    }
                };

                barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
                var bitmap = barcodeWriter.Write(text);
                var stream = new MemoryStream();
                bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);  // this is the diff between iOS and Android
                stream.Position = 0;

                byte[] imageData = stream.ToArray();

                string filePath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures) + $"/{filename}.png";


                System.IO.File.WriteAllBytes(filePath, imageData);
                //mediascan adds the saved image into the gallery
                var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);

                Intent sendIntent = new Intent(global::Android.Content.Intent.ActionSend);
                sendIntent.SetFlags(ActivityFlags.NewTask);
                sendIntent.PutExtra(global::Android.Content.Intent.ExtraText, description);

                sendIntent.SetType("image/*");

                //Uri apkURI = FileProvider.GetUriForFile(
                //            CrossCurrentActivity.Current.AppContext,
                //            CrossCurrentActivity.Current.AppContext.ApplicationContext
                //            .PackageName + ".provider",);
                // sendIntent.SetDataAndType(apkURI, mimeType);
                sendIntent.AddFlags(ActivityFlags.GrantReadUriPermission);

                sendIntent.PutExtra(Intent.ExtraStream, Android.Net.Uri.Parse("file://" + filePath));
                CrossCurrentActivity.Current.Activity.StartActivity(Intent.CreateChooser(sendIntent, "Compartilhando o qrcode"));
                return(Task.FromResult(0));
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.ToString());
                return(null);
            }
        }
コード例 #8
0
        private void DisplayConfirmation(string confString)
        {
            var writer = new ZXing.Mobile.BarcodeWriter();

            writer.Format         = BarcodeFormat.QR_CODE;
            writer.Options        = new QrCodeEncodingOptions();
            writer.Options.Width  = 512;
            writer.Options.Height = 512;

            var code = writer.Write(confString);

            SetContentView(Resource.Layout.QrLayout);

            var confObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Confirmation>(confString);

            var imageView = FindViewById <ImageView>(Resource.Id.qrImageView);

            imageView.SetImageBitmap(code);

            var btn = FindViewById <Button>(Resource.Id.qrButton);

            btn.Text = "Zpìt do menu";

            var allTasks = new List <ChallengeTask>();

            foreach (var c in AppState.State.Instance.Challenges)
            {
                allTasks.AddRange(c.BasicTasks);
                allTasks.AddRange(c.ExtraTasks);
            }

            var targetName = (confObject.Request.Type == ConfirmationType.Challenge
                ? AppState.State.Instance.Challenges
                              .ToList()[confObject.Request.TargetId].Names[0].Name
                : allTasks.FirstOrDefault(t => t.Id == confObject.Request.TargetId)?.Name);

            Model.User targetUser;
            using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath))
            {
                targetUser = db.Find <Model.User>(confObject.Request.UserId);
            }

            var text = FindViewById <TextView>(Resource.Id.qrScanRequestText);

            text.Text = "Potvrzení " + (confObject.Request.Type == ConfirmationType.Challenge ? "zkoušky " : "úkolu ") + targetName
                        + " pro uživatele " + targetUser.Name;

            btn.Click += (o, e) =>
            {
                SetResult(Android.App.Result.Ok);
                Finish();
            };
        }
コード例 #9
0
ファイル: Barcode.cs プロジェクト: cpen442/OneTimeBarcode
        private Bitmap makeBarcode(string data)
        {
            var writer = new ZXing.Mobile.BarcodeWriter
            {
                Format  = BarcodeFormat.PDF_417,
                Options = new EncodingOptions {
                    Width = 1000, Height = 400
                }
            };

            return(writer.Write(data));
        }
コード例 #10
0
        public async void  SaveImage(ZXingBarcodeImageView image)
        {
            var writer = new ZXing.Mobile.BarcodeWriter();

            if (image != null && image.BarcodeOptions != null)
            {
                writer.Options = image.BarcodeOptions;
            }
            if (image != null)
            {
                writer.Format = image.BarcodeFormat;
            }
            var value = image != null ? image.BarcodeValue : string.Empty;
            var wb    = writer.Write(value);

            //var imageData = ImagetoBytes(wb);
            var filename = System.DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";

            if (Device.Idiom == TargetIdiom.Desktop)
            {
                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
                savePicker.SuggestedStartLocation =
                    Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
                savePicker.SuggestedFileName = filename;
                savePicker.FileTypeChoices.Add("JPEG Image", new List <string>()
                {
                    ".jpg"
                });

                var file = await savePicker.PickSaveFileAsync();

                if (file != null)
                {
                    CachedFileManager.DeferUpdates(file);
                    await ConvertToJPEGFileAsync(file, wb);

                    var status = await CachedFileManager.CompleteUpdatesAsync(file);

                    if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                    {
                        ShowToastNotification();
                    }
                }
            }
            else
            {
                StorageFolder storageFolder = KnownFolders.SavedPictures;
                StorageFile   sampleFile    = await storageFolder.CreateFileAsync(
                    filename + ".jpg", CreationCollisionOption.ReplaceExisting);
                await ConvertToJPEGFileAsync(sampleFile, wb);
            }
        }
コード例 #11
0
        private Bitmap GetQRCode()
        {
            var writer = new ZXing.Mobile.BarcodeWriter();

            writer.Format         = ZXing.BarcodeFormat.QR_CODE;
            writer.Options.Margin = 1;
            writer.Options.Height = 300;
            writer.Options.Width  = 300;



            return(writer.Write(ipadre));
        }
コード例 #12
0
        private Android.Graphics.Bitmap GetQRCode()
        {
            var writer = new ZXing.Mobile.BarcodeWriter();

            writer.Format         = ZXing.BarcodeFormat.QR_CODE;
            writer.Options.Margin = 1;
            writer.Options.Height = 500;
            writer.Options.Width  = 500;



            return(writer.Write(miip + "¤" + mipuertoquerry + "¤" + mipuertoarchivo + "¤" + SettingsHelper.GetSetting("rutadescarga") + "¤" + Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/"));
        }
コード例 #13
0
        async void IDownloadImage.CopyImage(ZXingBarcodeImageView image)
        {
            EmailMessage emailMessage = new EmailMessage();

            string messageBody = "Hello World";

            emailMessage.Body = messageBody;

            var writer = new ZXing.Mobile.BarcodeWriter();

            if (image != null && image.BarcodeOptions != null)
            {
                writer.Options = image.BarcodeOptions;
            }
            if (image != null)
            {
                writer.Format = image.BarcodeFormat;
            }
            var         value    = image != null ? image.BarcodeValue : string.Empty;
            var         wb       = writer.Write(value);
            StorageFile tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Barcode_Temp.jpeg", CreationCollisionOption.ReplaceExisting);

            if (tempFile != null)
            {
                CachedFileManager.DeferUpdates(tempFile);
                await ConvertToJPEGFileAsync(tempFile, wb);

                var status = await CachedFileManager.CompleteUpdatesAsync(tempFile);

                var dataPackage = new DataPackage();

                dataPackage.SetStorageItems(new List <IStorageItem>()
                {
                    tempFile
                });
                dataPackage.RequestedOperation = DataPackageOperation.Copy;
                Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
                ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();
                Windows.Data.Xml.Dom.XmlDocument toastXml      = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
                Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");
                toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Image Copied"));
                toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode("Image Copied Successfully"));
                Windows.Data.Xml.Dom.IXmlNode   toastNode = toastXml.SelectSingleNode("/toast");
                Windows.Data.Xml.Dom.XmlElement audio     = toastXml.CreateElement("audio");
                audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS");

                ToastNotification toast = new ToastNotification(toastXml);
                toast.ExpirationTime = DateTime.Now.AddSeconds(4);
                ToastNotifier.Show(toast);
            }
        }
コード例 #14
0
        private Bitmap GetQRCode()
        {
            var writer = new ZXing.Mobile.BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = new EncodingOptions
                {
                    Height = 600,
                    Width  = 600
                }
            };

            return(writer.Write(QRBurstAddress.Text));
            // Create your application here
        }
コード例 #15
0
ファイル: Saver.cs プロジェクト: kotikmoi/StoreHouse
        public bool Save(string data)
        {
            var SaveQRComplete = new TaskCompletionSource <bool>();

            try
            {
                var barcodeWriter = new ZXing.Mobile.BarcodeWriter
                {
                    Format  = ZXing.BarcodeFormat.QR_CODE,
                    Options = new ZXing.Common.EncodingOptions
                    {
                        Width  = 1000,
                        Height = 1000,
                        Margin = 10
                    }
                };

                barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
                var bitmap = barcodeWriter.Write(data);
                var stream = new MemoryStream();
                bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);  // this is the diff between iOS and Android
                stream.Position = 0;

                byte[] imageData = stream.ToArray();

                var dir      = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);
                var pictures = dir.AbsolutePath;
                //adding a time stamp time file name to allow saving more than one image... otherwise it overwrites the previous saved image of the same name
                string name     = "MY_QR" + System.DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
                string filePath = System.IO.Path.Combine(pictures, name);

                System.IO.File.WriteAllBytes(filePath, imageData);
                //mediascan adds the saved image into the gallery
                var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                mediaScanIntent.SetData(Android.Net.Uri.FromFile(new Java.IO.File(filePath)));

                Xamarin.Forms.Forms.Context.SendBroadcast(mediaScanIntent);
                SaveQRComplete.SetResult(true);
                return(SaveQRComplete.Task.Result);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.ToString());
                return(false);
            }
        }
コード例 #16
0
        public void SetQRInfo(string info)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = 1000,
                    Height = 1000,
                    Margin = 0
                }
            };

            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
            var bitmap = barcodeWriter.Write(info);

            imageView.Image = bitmap;
        }
コード例 #17
0
        public static Android.Graphics.Bitmap GetQrCode(string sData, int iWidth, int iHeight, int iMargin = 0)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width       = iWidth,
                    Height      = iHeight,
                    Margin      = iMargin,
                    PureBarcode = true
                }
            };

            var barcode = barcodeWriter.Write("!" + sData);

            return(barcode);
        }
コード例 #18
0
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.ImageActivity);

            imageBarcode = FindViewById<ImageView> (Resource.Id.imageBarcode);

            var barcodeWriter = new ZXing.Mobile.BarcodeWriter {
                Format = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions {
                    Width = 300,
                    Height = 300
                }
            };
            var barcode = barcodeWriter.Write ("ZXing.Net.Mobile");

            imageBarcode.SetImageBitmap (barcode);
        }
コード例 #19
0
        public async Task <byte[]> DisplayImageAsync(ZXingBarcodeImageView image)
        {
            var writer = new ZXing.Mobile.BarcodeWriter();

            if (image != null && image.BarcodeOptions != null)
            {
                writer.Options = image.BarcodeOptions;
            }
            if (image != null)
            {
                writer.Format = image.BarcodeFormat;
            }
            var value = image != null ? image.BarcodeValue : string.Empty;
            var wb    = writer.Write(value);

            byte [] x = await ImagetoBytesAsync(wb);

            return(x);
        }
コード例 #20
0
        private void btnGenAddress_Click(object sender, RoutedEventArgs e)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = 300,
                    Height = 300
                }
            };

            GenerateAddressTopic();
            GenerateAddressUrl(topic);

            var barcode = barcodeWriter.Write(url);

            qrImage.Source = barcode;
        }
コード例 #21
0
ファイル: ImageActivity.cs プロジェクト: annv2601/QuetmaVach
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.ImageActivity);

            imageBarcode = FindViewById <ImageView> (Resource.Id.imageBarcode);

            var barcodeWriter = new ZXing.Mobile.BarcodeWriter {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions {
                    Width  = 300,
                    Height = 300
                }
            };
            var barcode = barcodeWriter.Write("ZXing.Net.Mobile");

            imageBarcode.SetImageBitmap(barcode);
        }
コード例 #22
0
        // UI initialization

        private void DisplayRequest(string requestJson)
        {
            var writer = new ZXing.Mobile.BarcodeWriter();

            writer.Format         = BarcodeFormat.QR_CODE;
            writer.Options        = new QrCodeEncodingOptions();
            writer.Options.Width  = 512;
            writer.Options.Height = 512;

            var code          = writer.Write(requestJson);
            var requestObject = Newtonsoft.Json.JsonConvert.DeserializeObject <ConfirmationRequest>(requestJson);

            SetContentView(Resource.Layout.QrLayout);

            var imageView = FindViewById <ImageView>(Resource.Id.qrImageView);

            imageView.SetImageBitmap(code);

            var btn = FindViewById <Button>(Resource.Id.qrButton);

            btn.Click           += (o, e) => ScanConfirmation();
            _onScanConfirmation += ProcessConfirmation;

            var allTasks = new List <ChallengeTask>();

            foreach (var c in AppState.State.Instance.Challenges)
            {
                allTasks.AddRange(c.BasicTasks);
                allTasks.AddRange(c.ExtraTasks);
            }

            var targetName = (requestObject.Type == ConfirmationType.Challenge
                ? AppState.State.Instance.Challenges
                              .ToList()[requestObject.TargetId].Names[0].Name
                : allTasks.FirstOrDefault(t => t.Id == requestObject.TargetId)?.Name);

            var text = FindViewById <TextView>(Resource.Id.qrScanRequestText);

            text.Text = $"Žádost o potvrzení "
                        + (requestObject.Type == ConfirmationType.Challenge ? "zkoušky " : "úkolu ") + targetName;
        }
コード例 #23
0
        public Stream ConvertImageStream(string text, int width = 300, int height = 300)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = width,
                    Height = height,
                    Margin = 3
                }
            };

            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
            var bitmap = barcodeWriter.Write(text);
            var stream = new MemoryStream();

            bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
            stream.Position = 0;
            return(stream);
        }
コード例 #24
0
        public System.IO.Stream GenerateBarCode(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 = 10
                }
            };

            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
            var bitmap = barcodeWriter.Write(text);
            var stream = new MemoryStream();

            bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);  // this is the diff between iOS and Android
            stream.Position = 0;
            return(stream);
        }
コード例 #25
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.Fragment2, container, false);

            imageBarcode = view.FindViewById <ImageView>(Resource.Id.imageBarcode);

            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = 300,
                    Height = 300
                }
            };
            var barcode = barcodeWriter.Write("Basel Abubaker");

            imageBarcode.SetImageBitmap(barcode);

            return(view);
        }
コード例 #26
0
        public Stream ConvertImageStream(string text, int width = 300, int height = 300)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = width,
                    Height = height,
                    Margin = 10
                }
            };

            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
            var bitmap = barcodeWriter.Write(text);
            var stream = bitmap.AsPNG().AsStream(); // this is the difference

            stream.Position = 0;

            return(stream);
        }
コード例 #27
0
        public byte[] GenerateQRCode(string content, int width = 250, int height = 250, int margin = 10)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = width,
                    Height = height,
                    Margin = margin,
                }
            };

            var image = barcodeWriter.Write(content);

            using (var imageData = image.AsPNG())
            {
                var bytes = new Byte[imageData.Length];
                Marshal.Copy(imageData.Bytes, bytes, 0, Convert.ToInt32(imageData.Length));
                return(bytes);
            }
        }
コード例 #28
0
ファイル: ImageService.cs プロジェクト: teyouale/Hunt
        public byte[] GenerateQRCode(string content, int width = 250, int height = 250, int margin = 10)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = width,
                    Height = height,
                    Margin = margin,
                }
            };

            var image = barcodeWriter.Write(content);

            using (var stream = new MemoryStream())
            {
                image.Compress(Bitmap.CompressFormat.Png, 0, stream);
                image = null;
                return(stream.ToArray());
            }
        }
コード例 #29
0
        public Stream GenerateQR(string text, int width = 300, int height = 300)
        {
            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width       = width,
                    Height      = height,
                    Margin      = 0,
                    PureBarcode = false
                }
            };

            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
            barcodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            var bitmap = barcodeWriter.Write(text);
            var stream = bitmap.AsPNG().AsStream();

            stream.Position = 0;

            return(stream);
        }
コード例 #30
0
        public void CompartilharCode(String dados)
        {
            if (Android.Support.V4.App.ActivityCompat.CheckSelfPermission(Android.App.Application.Context, Android.Manifest.Permission.WriteExternalStorage) != (int)Android.Content.PM.Permission.Granted)
            {
                Android.Support.V4.App.ActivityCompat.RequestPermissions(mainActivity, new string[] { Android.Manifest.Permission.WriteExternalStorage }, 0);

                return;
            }
            else
            {
                try
                {
                    String path       = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
                    String arquivoPDF = System.IO.Path.Combine(path, "code_participante.pdf");

                    FileStream fs       = new FileStream(arquivoPDF, FileMode.Create);
                    Document   document = new Document(PageSize.A4, 25, 25, 30, 30);
                    PdfWriter  writer   = PdfWriter.GetInstance(document, fs);

                    document.Open();

                    Paragraph cabecalho = new Paragraph();
                    cabecalho.Alignment = iTextSharp.text.Element.ALIGN_CENTER;

                    Phrase lblEvento = new Phrase("Evento XXX \n\n\n", new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 18f, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK));
                    Phrase lblNome   = new Phrase(dados.Split(';')[1] + "\n\n", new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 15f, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK));

                    cabecalho.Add(lblEvento);
                    cabecalho.Add(lblNome);

                    document.Add(cabecalho);

                    Paragraph pImg = new Paragraph();
                    pImg.Alignment = iTextSharp.text.Element.ALIGN_CENTER;

                    MemoryStream ms = new MemoryStream();

                    var bw = new ZXing.Mobile.BarcodeWriter();
                    bw.Options = new ZXing.Common.EncodingOptions()
                    {
                        Width = 600, Height = 250, Margin = 0
                    };
                    bw.Format   = ZXing.BarcodeFormat.QR_CODE;
                    bw.Renderer = new ZXing.Mobile.BitmapRenderer();

                    var bitmap = bw.Write(dados);
                    bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 0, ms);
                    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms.ToArray());
                    img.ScalePercent(60f);
                    img.Alignment = iTextSharp.text.Element.ALIGN_CENTER;

                    pImg.Add(img);

                    document.Add(pImg);

                    document.NewPage();

                    ms.Close();

                    document.Close();
                    writer.Close();
                    fs.Close();

                    var fileUri       = Android.Net.Uri.FromFile(new Java.IO.File(arquivoPDF));
                    var sharingIntent = new Intent();
                    sharingIntent.SetAction(Intent.ActionSend);
                    sharingIntent.SetType("application/pdf");
                    //sharingIntent.PutExtra(Intent.ExtraText, content);
                    sharingIntent.PutExtra(Intent.ExtraStream, fileUri);
                    //sharingIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
                    Intent intent = Intent.CreateChooser(sharingIntent, "code_participante.pdf");
                    intent.AddFlags(ActivityFlags.NewTask);
                    Android.App.Application.Context.StartActivity(intent);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }