Magick.NET库测试

cs 复制代码
        private void button4_Click(object sender, EventArgs e)
        {
            uint width = 100;
            uint height = 100;
            int[,] pixels = new int[height, width];
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // 示例:生成简单的渐变效果
                    byte red = (byte)(x * 255 / width);
                    byte green = (byte)(y * 255 / height);
                    byte blue = (byte)((x + y) * 255 / (width + height));
                    pixels[y, x] = (red << 16) | (green << 8) | blue; // RGB格式存储为整数
                }
            }
            using (var image = new MagickImage(MagickColor.FromRgba(0, 0, 0, 255), width, height))
            {
                for (var y = 0; y < height; y++)
                {
                    for (var x = 0; x < width; x++)
                    {
                        int pixelValue = pixels[y, x];
                        byte r = (byte)((pixelValue >> 16) & 0xFF);
                        byte g = (byte)((pixelValue >> 8) & 0xFF);
                        byte b = (byte)((pixelValue >> 0) & 0xFF);
                        Pixel p = new Pixel(x, y, new byte[] { r, g, b });
                        image.GetPixels().SetPixel(p);
                    }
                }
                image.Settings.Font = this.Font.Name;
                image.Settings.FillColor = MagickColors.Red;
                image.Settings.StrokeColor = MagickColors.Red;
                image.Annotate("test",Gravity.Center);
                image.Write("D:\\1.bmp");
                image.Format = MagickFormat.Bmp;
                using (var stream = new MemoryStream())
                {
                    image.Write(stream);
                    stream.Position = 0;
                    var bitmap = new Bitmap(stream);
                    pictureBox1.Image?.Dispose();
                    pictureBox1.Image = bitmap;
                }
            }
        }

生成图像大小可40000x40000,对大size图像支持较好,并实现了高斯模糊、Resize、裁剪、压缩、旋转等常见操作。

相关推荐
2601_962064701 天前
【报表查询】.NET开源ORM框架 SqlSugar 系列
开源·.net
ChaITSimpleLove2 天前
.NET 10 的 AI 技术栈全景:M.E.AI、MCP 与 Agent Framework 深度解析
人工智能·.net·ai agent·mcp·agent framework·m.e.ai·hosted agents
数据知道2 天前
.NET 反序列化漏洞——ViewState 与 BinaryFormatter 实战深度剖析
网络·网络安全·.net
leonkay3 天前
C# 特性(Attribute)——【1】基础讲解
开发语言·青少年编程·面试·c#·.net·个人开发
界面开发小八哥3 天前
界面控件DevExpress WinForms中文帮助文档 - 将基于DevExpress的.NET Framework应用迁移至最新版.NET
ui·.net·界面控件·winform·devexpress·ui开发
人丰3 天前
血泪复盘:一次由 HttpContext.Current 引发的 CPU 100% 惨案
性能优化·.net
ChaITSimpleLove3 天前
用 .NET 10 技术栈 “玩转 AI 学习” 的路线图:从 Minimal API 到 AI Agent 产品
人工智能·.net·学习 ai
半亩码田4 天前
【.NET新特性·第14篇】.NET 10 运行时与 SDK 新特性
.net
祀爱4 天前
C# MQTT 连接服务
后端·c#·.net