コード例 #1
0
ファイル: GetCode39.cs プロジェクト: KittenCN/TiffanyPurchase
        public Bitmap GetUnCodeBitmap(string UnCode)
        {
            EncodingOptions options = null;
            BarcodeWriter   writer  = null;

            options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 100,
                Height       = 60
            };
            writer         = new BarcodeWriter();
            writer.Format  = BarcodeFormat.CODE_128;
            writer.Options = options;
            Bitmap bitmap = writer.Write(UnCode);

            return(bitmap);
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter();
            writer.Format = ZXing.BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI   = true;
            options.CharacterSet = "UTF-8";
            options.Width        = 150;
            options.Height       = 150;
            writer.Options       = options;
            string tree_id = context.Request.QueryString["tree_id"];

            #region get URL
            //string AbsoluteUri = context.Request.Url.AbsoluteUri;
            //Uri uri = new Uri(AbsoluteUri);
            //string url = "http://" + uri.Host + "/" + uri.Segments[1] + "mobile/szum/TreeMessage.aspx?id=" + tree_id;
            //if (context.Request.IsLocal)
            //{
            //    IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
            //    IPAddress ipAddr = ipHost.AddressList[1];
            //    //url = url.Replace("localhost", ipAddr.ToString());
            //    url = url.Replace("localhost","192.168.3.27");
            //}
            //string result = url;
            #endregion

            #region get json
            Person p = new Person()
            {
                Name = "zhangsan", Age = 1
            };
            string json   = Newtonsoft.Json.JsonConvert.SerializeObject(p);
            string result = json;
            #endregion

            Bitmap b = writer.Write(result);
            //将图片验证码保存为流Stream返回
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            b.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            context.Response.BinaryWrite(ms.ToArray());
        }
コード例 #3
0
        public override Bitmap Build(string text, Parameters parm)
        {
            var QRParameters = (QRParameters)parm;

            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = QRParameters.BM;
            //设置二维码的宽度和高度
            options.Width  = QRParameters.DX;
            options.Height = QRParameters.DX;
            options.Margin = 0;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            if (QRParameters.RC == 7)
            {
                options.ErrorCorrection = ErrorCorrectionLevel.L;
            }
            if (QRParameters.RC == 15)
            {
                options.ErrorCorrection = ErrorCorrectionLevel.M;
            }
            if (QRParameters.RC == 25)
            {
                options.ErrorCorrection = ErrorCorrectionLevel.Q;
            }
            if (QRParameters.RC == 30)
            {
                options.ErrorCorrection = ErrorCorrectionLevel.H;
            }
            writer.Options = options;

            Bitmap map = writer.Write(text);

            map = Comm.Images.Covert(map, QRParameters.QJS, QRParameters.BJS);

            return(map);
        }
コード例 #4
0
ファイル: ZXingHelper.cs プロジェクト: Damon1989/DFramework
        /// <summary>
        /// 生成图片
        /// </summary>
        /// <param name="content"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="margin"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        private static Bitmap GenerateBitmap(string content, int width, int height, int margin, BarcodeFormat format)
        {
            //设置QR二维码的规格
            var qrCodeEncodingOptions = new QrCodeEncodingOptions
            {
                CharacterSet = "UTF-8",
                Width        = width,
                Height       = height,
                Margin       = margin
            };

            // 生成条形码图片
            var writer = new BarcodeWriter
            {
                Format  = format,
                Options = qrCodeEncodingOptions
            };

            return(writer.Write(content));
        }
コード例 #5
0
ファイル: ImageUtils.cs プロジェクト: ahuinan/MyCode
        /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="content">生成内容</param>
        /// <returns></returns>
        public static Bitmap CreateImgCode(string content)
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = 255;
            options.Height = 255;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;
            Bitmap image = writer.Write(content);

            return(image);
        }
コード例 #6
0
        public main_menu()
        {
            if (!String.IsNullOrEmpty(Properties.Settings.Default.Lan1))
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Lan1);
                System.Threading.Thread.CurrentThread.CurrentCulture   = System.Globalization.CultureInfo.GetCultureInfo(Properties.Settings.Default.Lan1);
            }
            InitializeComponent();
            options4QR = new QrCodeEncodingOptions() //параметры кодировки (coding parameters)
            {
                DisableECI   = true,                 //usefil
                CharacterSet = "UTF-8",              //type of coding
                Width        = l,                    //user input
                Height       = f,                    //user input
            };
            var cscodewriter = new BarcodeWriter();

            cscodewriter.Format  = BarcodeFormat.QR_CODE;
            cscodewriter.Options = options4QR;
        }
        public Form1()
        {
            InitializeComponent();

            // Step 2: Coding in your Form Load
            //For Width or Height, you can change it to any value you want. :)
            //Note: Please write this first:
            //QrCodeEncodingOptions options = new QrCodeEncodingOptions();
            options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 250,
                Height       = 250,
            };
            var writer = new BarcodeWriter();

            writer.Format  = BarcodeFormat.QR_CODE;
            writer.Options = options;
        }
コード例 #8
0
        public static ImageSource GenQrCode(string content, int width, int height)
        {
            var options = new QrCodeEncodingOptions
            {
                DisableECI      = true,
                CharacterSet    = @"UTF-8",
                Width           = width,
                Height          = height,
                Margin          = 0,
                ErrorCorrection = ErrorCorrectionLevel.H
            };
            var write = new BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = options
            };
            var bitmap = write.Write(content);

            return(ToBitmapImage(bitmap));
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: monders00/hello-world.
        /// <summary>
        /// 生成二维码,保存成图片
        /// </summary>
        static void Generate1(string text)
        {
            BarcodeWriter writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();
            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width = 500;
            options.Height = 500;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;

            Bitmap map = writer.Write(text);
            string filename = @"H:\桌面\截图\generate1.png";
            map.Save(filename, ImageFormat.Png);
            map.Dispose();
        }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: meishimeike/QRcode
        /// <summary>
        /// 生成二维码,保存成图片
        /// </summary>
        static Bitmap Generate1(string text)
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = 400;
            options.Height = 400;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;
            Bitmap map = writer.Write(text);

            return(map);
        }
コード例 #11
0
ファイル: QRCode.cs プロジェクト: RelinkaKing/UnityPC
    /// <summary>
    /// 返回对应颜色数组
    /// </summary>
    /// <param name="s_formatStr">扫码信息</param>
    /// <param name="s_width">码宽</param>
    /// <param name="s_height">码高</param>
    Color32[] GeneQRCode(string s_formatStr, int s_width, int s_height)
    {
        //设置中文编码格式,否则中文不支持
        QrCodeEncodingOptions tOptions = new QrCodeEncodingOptions();

        tOptions.CharacterSet = "UTF-8";
        //设置宽高
        tOptions.Width  = s_width;
        tOptions.Height = s_height;
        //设置二维码距离边缘的空白距离
        tOptions.Margin = 3;

        //重置申请写二维码变量类       (参数为:码格式(二维码、条形码...)    编码格式(支持的编码格式)    )
        m_barcodeWriter = new BarcodeWriter {
            Format = BarcodeFormat.QR_CODE, Options = tOptions
        };

        //将咱们需要隐藏在码后面的信息赋值上
        return(m_barcodeWriter.Write(s_formatStr));
    }
コード例 #12
0
ファイル: GenerateBarcode.cs プロジェクト: SashaKoragin/My
        /// <summary>
        /// Генерация QR CODE
        /// </summary>
        /// <param name="fullPathAndNameFileNotFormat">Путь сохранения</param>
        /// <param name="templateContent"></param>
        /// <returns>Полный путь сохранения</returns>
        public string GenerateQrCode(string fullPathAndNameFileNotFormat, string templateContent)
        {
            fullPathAndNameFileNotFormat = fullPathAndNameFileNotFormat + WordConstant.FormatPng;
            var options = new QrCodeEncodingOptions()
            {
                GS1Format    = false,
                DisableECI   = false,
                PureBarcode  = false,
                CharacterSet = "UTF-8",
                Width        = 120,
                Height       = 120,
                Margin       = 0
            };
            var writer = new BarcodeWriter();

            writer.Format  = BarcodeFormat.QR_CODE;
            writer.Options = options;
            writer.Write(templateContent).Save(fullPathAndNameFileNotFormat);
            return(fullPathAndNameFileNotFormat);
        }
コード例 #13
0
ファイル: frmBarCode.cs プロジェクト: hoangtamit/NKV
        private void frmBarCode_Load(object sender, EventArgs e)
        {
            tbl = new DataTable();
            tbl = bqrCtr.BarcodeQr_LoadData();
            gridControl1.DataSource = tbl;


            options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = (int)txtChieuRong.Value,
                Height       = (int)txtChieuDai.Value,
            };
            writer = new BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = options
            };
        }
コード例 #14
0
        public System.Web.Mvc.FileResult GetBarcode(string code, int codeType = (int)ZXing.BarcodeFormat.CODE_128)
        {
            var options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 300,
                Height       = 100
            };

            var qr = new ZXing.BarcodeWriter();

            qr.Options = options;
            qr.Format  = (ZXing.BarcodeFormat)codeType;
            var img = new Bitmap(qr.Write(code));

            var bytes = Helper.ConvertToByteArray(img);

            return(File(bytes, "image/png"));
        }
コード例 #15
0
ファイル: FrmExample.cs プロジェクト: presscad/BaseLayer
        //生成二维码
        private void btnCreateD1_Click(object sender, EventArgs e)
        {
            EncodingOptions options = null;
            BarcodeWriter   writer  = null;

            options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = picD2.Width,
                Height       = picD2.Height
            };
            writer         = new BarcodeWriter();
            writer.Format  = BarcodeFormat.QR_CODE;
            writer.Options = options;

            Bitmap bitmap = writer.Write(txtD2.Text);

            picD2.Image = bitmap;
        }
コード例 #16
0
        /// <summary>
        /// ¸ù¾Ý×Ö·û´®Éú³É¶þάÂë
        /// </summary>
        /// <param name="content">×Ö·û´®</param>
        /// <returns></returns>
        public Bitmap CreateQRCode(string content)
        {
            //StringBuilder sbCode = new StringBuilder(content.Length + 3);
            //sbCode.Append(content);
            Dictionary <EncodeHintType, object> hints = new Dictionary <EncodeHintType, object>();

            hints[EncodeHintType.CHARACTER_SET] = "UTF-8";
            BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, _qrSize.Width, _qrSize.Height, hints);

            matrix = CutWhiteBorder(matrix);
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.CharacterSet    = "UTF-8";
            options.DisableECI      = true;
            options.ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H;
            options.Margin          = 1;

            ConfigSave    config = Program.MainForm.Config;
            BarcodeWriter writer = new BarcodeWriter();

            writer.Renderer = new ZXing.Rendering.BitmapRenderer {
                Foreground = config.QRSetColor, Background = config.QRBackSetColor
            };
            writer.Format  = BarcodeFormat.QR_CODE;
            writer.Options = options;

            writer.Options.Width  = matrix.Width;
            writer.Options.Height = matrix.Height;


            Bitmap bmp = writer.Write(matrix);

            if (bmp.Size == _qrSize)
            {
                return(bmp);
            }
            Bitmap ret = Picture.ReSizePicturee(bmp, _qrSize.Width, _qrSize.Height);

            bmp.Dispose();
            return(ret);
        }
コード例 #17
0
        private static void CreateQRCode(string content, string file)
        {
            EncodingOptions options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 300,
                Height       = 300
            };

            var writer = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,

                Options = options
            };

            Bitmap bitmap = writer.Write(content);

            bitmap.Save(file, ImageFormat.Jpeg);
        }
コード例 #18
0
        /// <summary>
        /// 生成二维码
        /// </summary>
        /// <param name="text">内容</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <returns></returns>
        public static Bitmap QRcode(string text, int width, int height)
        {
            BarcodeWriter writer = new BarcodeWriter()
            {
            };                                             // { Format = BarcodeFormat.QR_CODE };

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions()
            {
                DisableECI   = true,    //设置内容编码
                CharacterSet = "UTF-8", //设置二维码的宽度和高度
                Width        = width,
                Height       = height,
                Margin       = 1//设置二维码的边距,单位不是固定像素
            };

            writer.Options = options;
            Bitmap map = writer.Write(text);

            return(map);
        }
コード例 #19
0
ファイル: QRcode.cs プロジェクト: wwkkww1983/WMS
        /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="codeNumber">要生成二维码的字符串</param>
        /// <param name="size">大小尺寸</param>
        /// <returns>二维码图片</returns>
        public Bitmap Create_ImgCode(string codeNumber, int size)
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = size;
            options.Height = size;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 0;
            writer.Options = options;

            Bitmap map = writer.Write(codeNumber);

            return(map);
        }
コード例 #20
0
        private void frmQuetBarcodeSticker_Load(object sender, EventArgs e)
        {
            thongtindonhang();
            truyendulieu();
            phanquyen();

            options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 300,
                Height       = 300,
            };
            writer = new BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = options
            };
            //txtNhap.Text = "ok";
            txtNhap.Focus();
        }
コード例 #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static Bitmap CreateCodeBitmap(string message, int width = 600, int height = 600)
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = width;
            options.Height = height;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;
            using (Bitmap map = writer.Write(message))
            {
                return(map);
            }
        }
コード例 #22
0
        public static Bitmap getCodeBitmap(string code)
        {
            EncodingOptions options = null;

            options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 465,
                Height       = 60
            };

            BarcodeWriter barcodeWriter = new BarcodeWriter();

            barcodeWriter.Format = BarcodeFormat.CODE_128;

            barcodeWriter.Options = options;
            Bitmap bitmap = barcodeWriter.Write(code);

            return(bitmap);
        }
コード例 #23
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim() == string.Empty)
            {
                MessageBox.Show("ENTER QR TEXT");
            }
            var options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 230,
                Height       = 230,
            };
            var qr = new ZXing.BarcodeWriter();

            qr.Options = options;
            qr.Format  = ZXing.BarcodeFormat.QR_CODE;
            var result = new Bitmap(qr.Write(textBox1.Text.Trim()));

            result.Save(@"C:\Users\Mohd\Downloads\sourcecode\Steganography\Sample QR CODE\sampleqr.bmp");
        }
コード例 #24
0
        /// <summary>
        /// 生成二维码,输出Bitmap对象(Bitmap map =CodeImage.QrCode("123"))
        /// </summary>
        /// <param name="content">二维码内容</param>
        public static Bitmap QrCode(string content, int Width = 500, int Height = 500)
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = Width;
            options.Height = Height;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;

            Bitmap map = writer.Write(content);

            return(map);
        }
コード例 #25
0
ファイル: PrintHelper.cs プロジェクト: 7soft-cn/HttpPrint
        /// <summary>
        /// 使用ZxingNet生成二维码图片
        /// </summary>
        /// <param name="codeContent">内容信息</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="imgType">ImageFormat imgType</param>
        /// <param name="BarcodeFormat barcodeFormat">barcodeFormat</param>
        /// <returns></returns>
        public Image NewQRCodeByZxingNet(string codeContent, int width, int height)
        {
            // 1.设置QR二维码的规格
            QrCodeEncodingOptions code = new QrCodeEncodingOptions();

            code.CharacterSet = "UTF-8"; // 设置编码格式,否则读取'中文'乱码
            code.Height       = height;
            code.Width        = width;
            code.Margin       = 1; // 设置周围空白边距

            // 2.生成条形码图片并保存
            BarcodeWriter wr = new BarcodeWriter();

            wr.Format  = BarcodeFormat.QR_CODE; // 二维码 BarcodeFormat.QR_CODE
            wr.Options = code;
            Bitmap bitImg = wr.Write(codeContent);

            //var bitImgWithTitle = addText(codeContent, bitImg);//底部加文字
            //return bitImgWithTitle;
            return(bitImg);
        }
コード例 #26
0
        public static string GenerateQR(string str, string serverpath = @"C:\", int width = 80, int height = 80)
        {
            //var checkfolder = CheckFolderExists(serverpath);
            string barcodeString = str;
            string path          = Path.GetTempFileName() + ".jpg";

            var writer = new ZXing.BarcodeWriterPixelData
            {
                Format = ZXing.BarcodeFormat.QR_CODE,
            };
            var options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = width,
                Height       = height,
            };

            writer.Options = options;
            var pixelData = writer.Write(barcodeString);

            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(path, ImageFormat.Jpeg);
                }
            return(path);
        }
コード例 #27
0
ファイル: Util.cs プロジェクト: GustavAT/Votor
        /// <summary>
        /// Generate QR code from given string with given width and height.
        /// </summary>
        /// <param name="content">Content</param>
        /// <param name="height">Height</param>
        /// <param name="width">Width</param>
        /// <returns>Base64 of the QR code</returns>
        public static string GenerateQrCode(string content, int width = 250, int height = 250)
        {
            var options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Height       = height,
                Width        = width
            };

            var writer = new BarcodeWriterPixelData
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = options
            };

            var pixelData = writer.Write(content);

            using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, PixelFormat.Format32bppRgb))
            {
                using (var stream = new 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(stream, ImageFormat.Png);
                    return(Convert.ToBase64String(stream.ToArray()));
                }
            }
        }
コード例 #28
0
        /// <summary>
        ///  生成带logo的二维码
        /// </summary>
        /// Author  : Napoleon
        /// Created : 2016-01-25 14:52:32
        private void BtnCreateLogoCode2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(TxtLogoUrl.Text))
            {
                MessageBox.Show("请选择logo图片!");
                return;
            }
            //设置QR二维码的规格
            QrCodeEncodingOptions qrEncodeOption = new QrCodeEncodingOptions();

            qrEncodeOption.CharacterSet = "UTF-8"; // 设置编码格式,否则读取'中文'乱码
            qrEncodeOption.Height       = 200;
            qrEncodeOption.Width        = 200;
            qrEncodeOption.Margin       = 1; //设置周围空白边距
            BarcodeWriter wr = new BarcodeWriter();

            wr.Format  = BarcodeFormat.QR_CODE; // 二维码
            wr.Options = qrEncodeOption;
            Bitmap img = wr.Write(TxtCode.Text);
            //在二维码的Bitmap对象上绘制logo图片
            Bitmap logoImg = Bitmap.FromFile(TxtLogoUrl.Text) as Bitmap;

            if (logoImg != null)
            {
                Graphics  g       = Graphics.FromImage(img);
                Rectangle logoRec = new Rectangle(); // 设置logo图片的大小和绘制位置
                logoRec.Width  = img.Width / 6;
                logoRec.Height = img.Height / 6;
                logoRec.X      = img.Width / 2 - logoRec.Width / 2; // 中心点
                logoRec.Y      = img.Height / 2 - logoRec.Height / 2;
                g.DrawImage(logoImg, logoRec);
            }
            PicCode.Image = img;
            if (!string.IsNullOrEmpty(TxtImgUrl.Text)) //地址不为空的话,需要将图片生成
            {
                string filePath = TxtImgUrl.Text + "\\QR-" + TxtCode.Text + ".jpg";
                img.Save(filePath, ImageFormat.Jpeg);
                MessageBox.Show("二维码已经生成并保存成功!");
            }
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: baominxing/Learning
        public static void Demonstration()
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = 70;
            options.Height = 70;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;

            using (Bitmap img = writer.Write("111111111-20C1601"))
            {
                img.Save($"{DateTime.Now.ToString("yyyyMMddHHmmss")}.png", ImageFormat.Png);
            }
        }
コード例 #30
0
ファイル: PirentZXingNet.cs プロジェクト: wryip/diyiban
        public static bool PirentTM(string str, string fuwuame, string dannumber, string datetime, int suncount, int index, string question, string type, string pinpai, string color, string remark)
        {
            _remark    = remark;
            _color     = color;
            _type      = type;
            _pinpai    = pinpai;
            _question  = question;
            _sumcount  = suncount;
            _sumindex  = index;
            _datetime  = datetime;
            _fuwuname  = fuwuame;
            _dannumber = dannumber;
            QrCodeEncodingOptions option;
            BarcodeWriter         writer = null;

            option = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 200,
                Height       = 100
            };
            writer = new BarcodeWriter();
            //writer.Format = BarcodeFormat.QR_CODE;//二维码
            writer.Format  = BarcodeFormat.ITF;//改变条形码条形码
            writer.Options = option;
            //str = str.Substring(0,str.Length-1);
            Bitmap bitmap = writer.Write(str);

            try
            {
                ceshi(bitmap);
                return(true);
            }
            catch
            {
                return(false);
            }
        }