Exemplo n.º 1
0
        /// <summary>
        /// 带图标二维码,加上图标后请把容错级别调高,这样可以提高识别成功率
        /// </summary>
        public static byte[] GetQrCodeWithIconBytes(this QrCode coder,
                                                    string content, string icon_path, int size = QrCode.QRCODE_SIZE)
        {
            if (!File.Exists(icon_path))
            {
                throw new Exception("二维码水印图片不存在");
            }
            var bs = coder.GetQrCodeBytes(content, size);

            using (var bm = ConvertHelper.BytesToBitmap(bs))
            {
                using (var g = Graphics.FromImage(bm))
                {
                    using (var logo = Image.FromFile(icon_path))
                    {
                        using (var smallLogo = logo.GetThumbnailImage(bm.Width / 5, bm.Height / 5, null, IntPtr.Zero))
                        {
                            //把压缩后的图片绘制到二维码上
                            g.DrawImage(smallLogo, (bm.Width - smallLogo.Width) / 2, (bm.Height - smallLogo.Height) / 2);
                        }
                    }
                }
                return(bm.ToBytes(coder.Formart));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 带图标二维码,加上图标后请把容错级别调高,这样可以提高识别成功率
        /// </summary>
        public static byte[] GetQrCodeWithIconBytes(this QrCode coder,
                                                    string content, string icon_path, int size = QrCode.QRCODE_SIZE)
        {
            if (!File.Exists(icon_path))
            {
                throw new Exception("二维码水印图片不存在");
            }
            var bs = coder.GetQrCodeBytes(content, size);

            bs = coder.AddIcon(bs, icon_path);
            return(bs);
        }