Пример #1
0
        void Merge(string addImageName)
        {
            SixLabors.ImageSharp.Image baseImage = SixLabors.ImageSharp.Image.Load(Path.Combine(temp_path, pictureBox1.Name));
            SixLabors.ImageSharp.Image addImage  = SixLabors.ImageSharp.Image.Load(Path.Combine(temp_path, addImageName));

            SixLabors.ImageSharp.Point toRight = new SixLabors.ImageSharp.Point(x: baseImage.Width, y: 0);
            SixLabors.ImageSharp.Point topLeft = new SixLabors.ImageSharp.Point(x: 0, y: 0);

            SixLabors.ImageSharp.Image newImage = new SixLabors.ImageSharp.Image <Rgba32>(baseImage.Width + addImage.Width, baseImage.Height);

            newImage = newImage.Clone(ipc =>
            {
                ipc.DrawImage(baseImage, topLeft, 1);
                ipc.DrawImage(addImage, toRight, 1);
            });
            using (MemoryStream memoryStream = new MemoryStream())
            {
                SixLabors.ImageSharp.Formats.IImageEncoder imageEncoder = newImage.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance);

                newImage.Save(memoryStream, imageEncoder);

                (new Bitmap(memoryStream)).Save(Path.Combine(temp_path, "generated.png"));
                Merge_Execution(new Bitmap(memoryStream));
            }
        }
Пример #2
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.ImageSharp.Point()
                        {
                            X = (img.Width - icon.Width) / 2,
                            Y = (img.Height - icon.Height) / 2
                        };
                        img.Mutate(x => x.DrawImage(icon, location, 1f));
                        img.Save(ms, new SixLabors.ImageSharp.Formats.Png.PngEncoder());
                    }
                }
                return(ms.ToArray());
            }
        }