Ejemplo 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);

            bs = coder.AddIcon(bs, icon_path);
            return(bs);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 随机调色
 /// </summary>
 public static byte[] AddRandomHue(this QrCode coder, byte[] bs)
 {
     using (var ms = new MemoryStream())
     {
         using (var img = SixLabors.ImageSharp.Image.Load(bs))
         {
             var ran = new Random((int)DateTime.Now.Ticks);
             img.Mutate(x => x.Hue(ran.RealNext(360 - 1)));
             img.Save(ms, new SixLabors.ImageSharp.Formats.Png.PngEncoder());
         }
         return(ms.ToArray());
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 随机调色
        /// </summary>
        public static byte[] AddRandomHue(this QrCode coder, byte[] bs)
        {
            using (var ms = new MemoryStream())
            {
                using (var factory = new ImageFactory(preserveExifData: false))
                {
                    var ran = new Random((int)DateTime.Now.Ticks);

                    factory.Load(bs).Hue(ran.RealNext(360 - 1)).Save(ms);
                }

                return(ms.ToArray());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加icon
        /// </summary>
        public static byte[] AddIcon(this QrCode coder, byte[] bs, string icon_path)
        {
            using (var ms = new MemoryStream())
            {
                using (var img = SixLabors.ImageSharp.Image.Load(bs))
                {
                    using (var icon = SixLabors.ImageSharp.Image.Load(icon_path))
                    {
                        icon.Mutate(x => x.Resize(width: img.Width / 5, height: img.Height / 5));

                        var location = new SixLabors.Primitives.Point()
                        {
                            X = (img.Width - icon.Width) / 2,
                            Y = (img.Height - icon.Height) / 2
                        };
                        img.Mutate(x => x.DrawImage(icon, 1, location));
                        img.Save(ms, new SixLabors.ImageSharp.Formats.Png.PngEncoder());
                    }
                }
                return(ms.ToArray());
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 给二维码添加背景图片
 /// </summary>
 public static byte[] AddBackgroundImage(this QrCode coder, byte[] bs, byte[] background,
                                         (double width_scale, double height_scale)?scale = null)