示例#1
0
        public void GenerateAndRecognizeBarcode()
        {
            var reader = new BarcodeReader()
            {
                AutoRotate  = true,
                TryInverted = true,
                Options     = new ZXing.Common.DecodingOptions()
                {
                    TryHarder       = true,
                    PossibleFormats = new List <BarcodeFormat> {
                        BarcodeFormat.PDF_417
                    }
                },
            };

            var data = $"00000000000@{Constants.Donee.LastName}@{Constants.Donee.FirstName}@M@{Constants.Donee.Id}@A@{Constants.Donee.DateOfBirth:dd/MM/yyyy}@26/10/1986";

            var writer = new BarcodeWriterGeneric
            {
                Format  = BarcodeFormat.PDF_417,
                Options = new PDF417EncodingOptions
                {
                    Height = 60,
                    Width  = 240,
                    Margin = 10
                }
            };
            var bitmap = writer.WriteAsBitmap(data);

            var elements = reader.Decode(bitmap);

            Assert.Equal(data, elements.Text);
        }
示例#2
0
        public static string GetBase64Barcode(this string barCode)
        {
            if (string.IsNullOrEmpty(barCode))
            {
                return(string.Empty);
            }

            var barcodeWriter = new BarcodeWriterGeneric
            {
                Format  = BarcodeFormat.CODE_128,
                Options = new EncodingOptions
                {
                    Height      = 30,
                    PureBarcode = true
                }
            };

            var matrix = barcodeWriter.Encode(barCode);

            var width  = matrix.Width;
            var height = matrix.Height;

            var image = new Image <Rgba32>(width, height);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    image[x, y] = matrix[x, y] ? Rgba32.Black : Rgba32.White;
                    //image.SetPixel(x, y, (matrix.get_Renamed(x,y).Equals(0) ? BLACK : WHITE));
                }
            }

            return(image.ToBase64String(SixLabors.ImageSharp.Formats.Jpeg.JpegFormat.Instance));
        }
示例#3
0
        public void CanReadImageWithQR()
        {
            var writer = new BarcodeWriterGeneric
            {
                Format = BarcodeFormat.QR_CODE,
            };

            var data = Guid.NewGuid().ToString();

            using var bitmap = writer.WriteAsBitmap(data);
            using var mem    = new MemoryStream();
            bitmap.Save(mem, ImageFormat.Png);

            using var http = new HttpClient();
            var qr = new QRCode(http);

            var result = qr.Decode(mem.ToArray());

            Assert.NotNull(result);
            Assert.Equal(data, result);
        }
    // Start is called before the first frame update
    void Start()
    {
        Texture2D texture = new Texture2D(500, 500);

        texture.filterMode = FilterMode.Bilinear;

        BarcodeWriterGeneric writer = new BarcodeWriterGeneric();

        writer.Format         = BarcodeFormat.QR_CODE;
        writer.Options.Width  = texture.width;
        writer.Options.Height = texture.height;
        writer.Options.Margin = 10;

        PsicologoDAO     psicologoDAO = new PsicologoDAO();
        List <Psicologo> psicologos   = psicologoDAO.Lista();


        if (psicologos.Count > 0)
        {
            Psicologo psicologo      = psicologos[0];
            string    representation = string.Format(
                "{0}\n{1}\n{2}\n{3}",
                psicologo.Nombre,
                psicologo.Correo,
                psicologo.Telefono,
                psicologo.Cedula
                );

            BitMatrix matrix = writer.Encode(representation);
            matrix.rotate180();
            ZXing.Common.BitArray row = new ZXing.Common.BitArray(matrix.RowSize);

            // get image data
            int width  = texture.width;
            int height = texture.height;

            for (int y = 0; y < height; y++)
            {
                row = matrix.getRow(y, row);
                row.reverse(); // they are backwards wtf?
                int[] pixels = row.Array;

                int int_i = 0;
                int bit_i = 0;
                for (int x = 0; x < width; x++)
                {
                    int  bit_mask  = 1 << bit_i++;
                    int  int_value = pixels[int_i];
                    bool bit_value = (int_value & bit_mask) == bit_mask;

                    if (bit_i > 31)
                    {
                        bit_i = 0;
                        int_i++;
                    }

                    UnityEngine.Color color;
                    if (bit_value)
                    {
                        color = UnityEngine.Color.black;
                    }
                    else
                    {
                        color = UnityEngine.Color.white;
                    }

                    texture.SetPixel(x, y, color);
                }
            }

            texture.Apply();
            image.texture = texture;
            //imageFitter.aspectRatio = 1.0f;
            //image.material.mainTexture = texture;
        }
    }