Beispiel #1
0
        internal void DrawImage(ref MemoryStream ms, string qrcode, int height, int weight)
        {
            Bitmap   bm = new Bitmap(weight, height);
            Graphics g  = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);
            var writer    = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.CODE_39,
                Options = new QrCodeEncodingOptions
                {
                    Height = barHeight,
                    Width  = barWidth,
                    Margin = 0
                }
            };

            writer.Format         = ZXing.BarcodeFormat.QR_CODE;
            writer.Options.Height = barHeight;
            writer.Options.Width  = barWidth;

            //bm = ConvertPixelDataToBitmap(writer.Write(qrcode));
            ms = ConvertPixelDataToMemoryStream(writer.Write(qrcode));
        }
Beispiel #2
0
        public static Bitmap Encode(string value, int width, int height, int margin)
        {
            int subStringSize = value.Length / 3;
            var str1          = value.Substring(0, subStringSize);
            var str2          = value.Substring(subStringSize, subStringSize);
            var str3          = value.Substring(subStringSize * 2, value.Length - subStringSize * 2);

            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = height,
                    Width  = width,
                    Margin = margin
                }
            };

            var red   = qrCodeWriter.Write(str1);
            var green = qrCodeWriter.Write(str2);
            var blue  = qrCodeWriter.Write(str3);

            var pixelWidth  = blue.Width;
            var pixelHeight = blue.Height;

            var bitmap = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format32bppRgb);

            SetBitmap(bitmap, red.Pixels, green.Pixels, blue.Pixels);

            return(bitmap);
        }
Beispiel #3
0
        //创建二维码
        public static void CreateQRCode(string fileName, string content, int height, int width, int margin)
        {
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions {
                    Height = height, Width = width, Margin = margin
                }
            };

            var pixelData = qrCodeWriter.Write(content);

            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                                                                    pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // save to stream as PNG
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                }
        }
Beispiel #4
0
        internal void DrawImage(ref System.DrawingCore.Bitmap bm, string qrcode)
        {
            Graphics g = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);
            var writer    = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.CODE_39,
                Options = new QrCodeEncodingOptions
                {
                    Height = barHeight,
                    Width  = barWidth,
                    Margin = 0
                }
            };

            writer.Format         = ZXing.BarcodeFormat.QR_CODE;
            writer.Options.Height = barHeight;
            writer.Options.Width  = barWidth;

            bm = ConvertPixelDataToBitmap(writer.Write(qrcode));
        }
Beispiel #5
0
        public static string TextToQrCode(string texto)
        {
            var writer = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Width           = 180,
                    Height          = 180,
                    Margin          = 0,
                    QrVersion       = 10,
                    ErrorCorrection = ErrorCorrectionLevel.L
                }
            };
            var pixelData = writer.Write(texto);

            using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, PixelFormat.Format32bppRgb))
            {
                using (var ms = new System.IO.MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
                    try
                    {
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }

                    bitmap.Save(ms, ImageFormat.Png);
                    return(Convert.ToBase64String(ms.ToArray()));
                }
            }
        }
        public byte[] GetDeviceProvisioningQrCode(PhoneClientData data, int height, int width, int margin)
        {
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions {
                    Height = height, Width = width, Margin = margin
                }
            };

            var pixelData = qrCodeWriter.Write(JsonConvert.SerializeObject(data));

            using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, PixelFormat.Format32bppRgb))
                using (var memoryStream = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                                                                    pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // save to stream as PNG
                    bitmap.Save(memoryStream, ImageFormat.Png);
                    return(memoryStream.ToArray());
                }
        }
        public void Geerate(string fileName)
        {

            var QrcodeContent = Data;

            var margin = 0;
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format = ZXing.BarcodeFormat.CODE_128,
                Options = new QrCodeEncodingOptions
                {
                    Height = this.Height,
                    Width = this.Weidth,
                    Margin = margin,
                    PureBarcode = true,
                }
            };

            var pixelData = qrCodeWriter.Write(QrcodeContent);
            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference   
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB   

            //using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))

            ////using (var ms = new FileStream(QrcodeContent + ".png", FileMode.OpenOrCreate, FileAccess.ReadWrite))
            //using (var ms = new MemoryStream())
            //{
            //    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            //    try
            //    {
            //        //    // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image   
            //        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
            //    }
            //    finally
            //    {
            //        bitmap.UnlockBits(bitmapData);
            //    }
            //    return ms;
            //}

            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))

            //using (var ms = new FileStream(QrcodeContent + ".png", FileMode.OpenOrCreate, FileAccess.ReadWrite))
            using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
            {
                var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                try
                {
                    //    // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image   
                    System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                }
                finally
                {
                    bitmap.UnlockBits(bitmapData);
                }
                bitmap.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
            }

        }
Beispiel #8
0
        public static byte[] CreateLabelQRCode(LabelInfo labelInfo, string AESKey, bool printUB = false)
        {
            var width        = 350; // width of the Qr Code
            var height       = 340; // height of the Qr Code
            var margin       = 0;
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format = ZXing.BarcodeFormat.DATA_MATRIX,
                //Format = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = height,
                    Width  = width,
                    Margin = margin
                }
            };
            string contentQRCode = string.Empty;

            //QR code on both MUB and UB label will follow the data size = 91 characters in total
            if (printUB)
            {
                contentQRCode = labelInfo.MarkingNo + "*" + labelInfo.NRIC.PadLeft(9, '0') + "*" + labelInfo.Name.PadLeft(60, '_') + "*" + labelInfo.DrugType + "*";
            }
            else
            {
                contentQRCode = labelInfo.MarkingNo.PadLeft(11, '0') + "*" + labelInfo.NRIC.PadLeft(9, '0') + "*" + labelInfo.Name.PadLeft(60, '_') + "*" + "_".PadLeft(8, '_');
            }

            //contentQRCode = labelInfo.MarkingNo + "*" + labelInfo.NRIC.PadLeft(9, '0') + "*" + labelInfo.Name.PadLeft(60, '_') + "*" + "_".PadLeft(8, '_');

            //var encryptContent = CommonUtil.EncryptString(contentQRCode, AESKey);
            //var pixelData = qrCodeWriter.Write(encryptContent);
            var pixelData = qrCodeWriter.Write(contentQRCode);

            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            var ms = new System.IO.MemoryStream();

            var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            try
            {
                // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
            }
            finally
            {
                bitmap.UnlockBits(bitmapData);
            }
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

            return(ms.ToArray());
        }
Beispiel #9
0
        public async Task <object> OnResponse(object response, ResultExecutingContext context, Dictionary <string, string> settings)
        {
            var result = response as Newskies.WebApi.Contracts.GetBarCodedBoardingPassesResponse;

            if (result == null)
            {
                return(await Task.FromResult(response));
            }
            foreach (var barcodedBP in result.BarCodedBoardingPasses)
            {
                if (barcodedBP.BarCode != null && !string.IsNullOrEmpty(barcodedBP.BarCode.BarCodeData))
                {
                    var barcodeWriter = new ZXing.BarcodeWriterPixelData
                    {
                        Format  = ZXing.BarcodeFormat.PDF_417,
                        Options = new ZXing.Common.EncodingOptions
                        {
                            Height = result.BarcodeHeight > 0 ? result.BarcodeHeight : 100,
                            Width  = result.BarcodeWidth > 0 ? result.BarcodeWidth : 300,
                            Margin = 0
                        }
                    };
                    var pixelData = barcodeWriter.Write(barcodedBP.BarCode.BarCodeData);

                    // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
                    // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
                    // the System.Drawing.Bitmap class is provided by the CoreCompat.System.Drawing package
                    using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, PixelFormat.Format32bppRgb))
                    {
                        using (var ms = new MemoryStream())
                        {
                            // lock the data area for fast access
                            var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
                            try
                            {
                                // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                                System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                            }
                            finally
                            {
                                bitmap.UnlockBits(bitmapData);
                            }
                            // save to stream as PNG
                            bitmap.Save(ms, ImageFormat.Png);
                            var base64string = String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray()));
                            barcodedBP.BarCode.BarCodeImageBase64 = base64string;
                        }
                    }
                }
            }
            return(await Task.FromResult(result));
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            // string url, string alt = "QR code", int height = 500, int width = 500, int margin = 0)
            var content = context.AllAttributes["content"].Value.ToString();
            var alt     = context.AllAttributes["alt"].Value.ToString();
            var width   = Convert.ToInt32(context.AllAttributes["width"] == null ? "500" : context.AllAttributes["width"].Value.ToString());
            var height  = Convert.ToInt32(context.AllAttributes["height"] == null ? "500" : context.AllAttributes["height"].Value.ToString());
            var margin  = Convert.ToInt32(context.AllAttributes["margin"] == null ? "500" : context.AllAttributes["margin"].Value.ToString());

            var qrWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions {
                    Height = height, Width = width, Margin = margin
                }
            };


            var pixelData = qrWriter.Write(content);

            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
            // the System.Drawing.Bitmap class is provided by the CoreCompat.System.Drawing package
            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    // lock the data area for fast access
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                                                                    pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // save to stream as PNG
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                    output.TagName = "img";
                    output.Attributes.Clear();
                    output.Attributes.Add("width", width);
                    output.Attributes.Add("height", height);
                    output.Attributes.Add("alt", alt);
                    output.Attributes.Add("src",
                                          String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                }
        }
Beispiel #11
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var QrcodeContent = context.AllAttributes["content"].Value.ToString();
            var alt           = context.AllAttributes["alt"].Value.ToString();
            var width         = 250; // width of the Qr Code
            var height        = 100; // height of the Qr Code
            //var margin = 0;
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                //Format = ZXing.BarcodeFormat.QR_CODE,
                Format  = ZXing.BarcodeFormat.CODE_128,
                Options = new QrCodeEncodingOptions
                {
                    Height      = height,
                    Width       = width,
                    PureBarcode = true,
                    //Margin = margin,
                    CharacterSet = "UTF-8"
                }
            };

            byte[] bytes             = Encoding.Default.GetBytes(QrcodeContent);
            string QrcodeContentUTF8 = Encoding.UTF8.GetString(bytes);
            var    pixelData         = qrCodeWriter.Write(QrcodeContentUTF8);

            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // save to stream as PNG
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    output.TagName = "img";
                    output.Attributes.Clear();
                    output.Attributes.Add("width", width);
                    output.Attributes.Add("height", height);
                    output.Attributes.Add("alt", alt);
                    output.Attributes.Add("src", String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                }
        }
Beispiel #12
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            // Pega a url informada
            var QrcodeContent = context.AllAttributes["content"].Value.ToString();
            // Pega o texto da imagem
            var alt = context.AllAttributes["alt"].Value.ToString();
            // Tamanho da imagem
            var width  = 250; // width of the Qr Code
            var height = 250; // height of the Qr Code
            var margin = 0;

            // Configurando o QR Code
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions {
                    Height = height, Width = width, Margin = margin
                }
            };
            // Gerando o QR Code
            var pixelData = qrCodeWriter.Write(QrcodeContent);

            // criando um bitmap a partir dos dados de pixel brutos; se apenas as cores preto e branco forem usadas, não faz diferença
            // que os dados de pixel são orientados para BGRA e o bitmap é inicializado com RGB
            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        // assumimos que o passo da linha do bitmap está alinhado com 4 bytes multiplicado pela largura da imagem
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                                                                    pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // salvar para transmitir como PNG
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    output.TagName = "img";
                    output.Attributes.Clear();
                    output.Attributes.Add("width", width);
                    output.Attributes.Add("height", height);
                    output.Attributes.Add("alt", alt);
                    output.Attributes.Add("src",
                                          String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                }
        }
Beispiel #13
0
 /// <summary>
 /// Gets the pixel data for the given QR atributes.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="margin">The margin.</param>
 /// <returns></returns>
 public static ZXing.Rendering.PixelData GetPixelData(string text, int width, int height, int margin = 0)
 {
     ZXing.BarcodeWriterPixelData qrCodeWriter = new ZXing.BarcodeWriterPixelData
     {
         Format  = ZXing.BarcodeFormat.QR_CODE,
         Options = new QrCodeEncodingOptions
         {
             Height          = height,
             Width           = width,
             Margin          = margin,
             ErrorCorrection = ErrorCorrectionLevel.L
         }
     };
     ZXing.Rendering.PixelData pixelData = qrCodeWriter.Write(text);
     return(pixelData);
 }
Beispiel #14
0
        public static System.Web.UI.WebControls.Image generate_barcode(string nazwa, string stanowisko, string telefon, string email)

        {
            StringBuilder vcard = new StringBuilder("MECARD:N:" + nazwa + ";");

            vcard.Append("ORG: YourCompany;");
            vcard.Append("TEL: " + telefon + ";");
            vcard.Append("EMAIL: " + email + ";");
            vcard.Append("NOTE:" + stanowisko + "; ;");


            string barCode = vcard.ToString();

            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = 250,
                    Width  = 250,
                    Margin = 0
                }
            };
            var pixelData = qrCodeWriter.Write(barCode);


            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }


                    System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());

                    return(imgBarCode);
                }
        }
Beispiel #15
0
 public IActionResult Index(BarcodeModel model)
 {
     try
     {
         string finalimg = string.Empty;
         var    content  = model.BarcodeValue;
         var    width    = 50;
         var    height   = 50;
         var    barcodeWriterPixelData = new ZXing.BarcodeWriterPixelData
         {
             Format  = ZXing.BarcodeFormat.UPC_A,
             Options = new QrCodeEncodingOptions
             {
                 Height = height,
                 Width  = width,
                 Margin = 0
             }
         };
         var pixelData = barcodeWriterPixelData.Write(content);
         using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
         {
             using (var memoryStream = new MemoryStream())
             {
                 var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                 try
                 {
                     System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                 }
                 finally
                 {
                     bitmap.UnlockBits(bitmapData);
                 }
                 bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                 finalimg = String.Format("data:image/png;base64,{0}", Convert.ToBase64String(memoryStream.ToArray()));
             }
         }
         ViewBag.BaseImage = finalimg;
         ViewBag.CodeValue = model.BarcodeValue;
         return(View());
     }
     catch (Exception ex)
     {
         ViewBag.Exception = ex.Message;
         return(View());
     }
 }
Beispiel #16
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var content = context.AllAttributes["content"].Value.ToString();
            var width   = int.Parse(context.AllAttributes["width"].Value.ToString());
            var height  = int.Parse(context.AllAttributes["height"].Value.ToString());

            var barcodeWriterPixelData = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = height,
                    Width  = width,
                    Margin = 0
                }
            };
            var pixelData = barcodeWriterPixelData.Write(content);

            using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
            {
                using (var memoryStream = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     System.Drawing.Imaging.ImageLockMode.WriteOnly,
                                                     System.Drawing.Imaging.PixelFormat.Format32bppRgb);

                    try
                    {
                        System.Runtime.InteropServices.Marshal.Copy
                            (pixelData.Pixels, 0, bitmapData.Scan0,
                            pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                    output.TagName = "img";
                    output.Attributes.Clear();
                    output.Attributes.Add("width", width);
                    output.Attributes.Add("height", height);
                    output.Attributes.Add("src", string.Format("data:image/png;base64,{0}", Convert.ToBase64String(memoryStream.ToArray())));
                }
            }
        }
Beispiel #17
0
        public async Task <Warehouse> AddQrCodeForWarehouse(Warehouse createdWarehouse)
        {
            var QrcodeContent = $"https://warehouse-manager.azurewebsites.net/#/pages/warehouse/details/{createdWarehouse.Id}";
            var width         = 250; // width of the Qr Code
            var height        = 250; // height of the Qr Code
            var margin        = 0;

            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions {
                    Height = height, Width = width, Margin = margin
                }
            };

            var pixelData = qrCodeWriter.Write(QrcodeContent);

            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                                                                    pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // save to stream as PNG
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                    createdWarehouse.QrCodeBase64    = String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray()));
                    DB.Entry(createdWarehouse).State = EntityState.Modified;
                    await DB.SaveChangesAsync();

                    return(createdWarehouse);
                }
        }
        public static async Task Main(string[] args)
        {
            var barcodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.CODE_128,
                Options = new EncodingOptions
                {
                    Height = 300,
                    Width  = 300,
                },
                Renderer = new PixelDataRenderer
                {
                }
            };

            var pixelData = barcodeWriter.Write("Hallo Barcode");

            using (var image = Image.LoadPixelData <Rgba32>(pixelData.Pixels, 300, 300))
                await image.SaveAsBmpAsync("barcode.bmp");
        }
        private string GenerateQrCode(object id)
        {
            var width        = 100;
            var height       = 100;
            var margin       = 0;
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions {
                    Height = height, Width = width, Margin = margin
                }
            };
            var pixelData = qrCodeWriter.Write(id.ToString());

            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
            using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                                     pixelData.Pixels.Length);
                    }
                    catch (Exception ex)
                    {
                        _loggingService.Log(ex);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }

                    bitmap.Save(ms, ImageFormat.Png);
                    return(ms.ToDataUrl());
                }
        }
Beispiel #20
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = QR_DIMENTION,
                    Width  = QR_DIMENTION,
                    Margin = QR_MARGIN
                }
            };

            ZXing.Rendering.PixelData pixelData = qrCodeWriter.Write(QrUrl);
            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    BitmapData bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // save to stream as PNG
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    output.TagName = "img";
                    output.Attributes.Clear();
                    output.Attributes.Add("width", QR_DIMENTION);
                    output.Attributes.Add("height", QR_DIMENTION);
                    output.Attributes.Add("alt", QrUrl);
                    output.Attributes.Add("src", string.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                }
        }
Beispiel #21
0
        public static string Generate(string url)
        {
            var qrWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions {
                    Height = 200, Width = 200, Margin = 5
                }
            };


            var pixelData = qrWriter.Write(url);

            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
            // the System.Drawing.Bitmap class is provided by the CoreCompat.System.Drawing package
            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    // lock the data area for fast access
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                                                                    pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // save to stream as PNG
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                    return($"data:image/png;base64,{Convert.ToBase64String(ms.ToArray())}");
                }
        }
Beispiel #22
0
        public static void Generate(string QrcodeContent, string fileName)
        {
            // Tamanho da imagem
            var width  = 250; // width of the Qr Code
            var height = 250; // height of the Qr Code
            var margin = 0;

            // Configurando o QR Code
            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions {
                    Height = height, Width = width, Margin = margin
                }
            };
            // Gerando o QR Code
            var pixelData = qrCodeWriter.Write(QrcodeContent);


            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height),
                                                     System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        // assumimos que o passo da linha do bitmap está alinhado com 4 bytes multiplicado pela largura da imagem
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0,
                                                                    pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // salvar para transmitir como PNG
                    bitmap.Save(AppDomain.CurrentDomain.BaseDirectory + $"\\{fileName}.PNG", System.Drawing.Imaging.ImageFormat.Png);
                }
        }
Beispiel #23
0
        //public void Process(TagHelperContext context, TagHelperOutput output)
        public string QrProcess(string qrText, string fileName)
        {
            var QrCodeDirectory = _configuration.GetConnectionString("QrCodeDirectory");

            //var QrcodeContent = context.AllAttributes["content"].Value.ToString();
            //var alt = context.AllAttributes["alt"].Value.ToString();
            var QrcodeContent = qrText;
            //var alt = context.AllAttributes["alt"].Value.ToString();
            var    width  = 50; // width of the Qr Code
            var    height = 50; // height of the Qr Code
            var    margin = 0;
            string path   = "";

            var qrCodeWriter = new ZXing.BarcodeWriterPixelData
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = height,
                    Width  = width,
                    Margin = margin
                }
            };
            var pixelData = qrCodeWriter.Write(QrcodeContent);

            // creating a bitmap from the raw pixel data; if only black and white colors are used it makes no difference
            // that the pixel data ist BGRA oriented and the bitmap is initialized with RGB
            using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
                using (var ms = new MemoryStream())
                {
                    var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    try
                    {
                        // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                        System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                    }
                    finally
                    {
                        bitmap.UnlockBits(bitmapData);
                    }
                    // save to stream as PNG
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);


                    byte[] bytes = ms.ToArray();

                    //Store QrCode on Server
                    //string path = Path.Combine(_hostingEnvironment.WebRootPath, "QrImages", fileName + ".png");
                    //System.IO.File.WriteAllBytes(path, bytes);

                    var _task = Task.Run(() => this.UploadFileToBlobAsync(fileName + ".png", bytes, "image/png", QrCodeDirectory));
                    _task.Wait();
                    path = _task.Result;

                    return(path);

                    //output.TagName = "img";
                    //output.Attributes.Clear();
                    //output.Attributes.Add("width", width);
                    //output.Attributes.Add("height", height);
                    //output.Attributes.Add("alt", alt);
                    //output.Attributes.Add("src", String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                    //string imgString = String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray()));
                    //return imgString;
                }
        }