·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 使用OctreeQuantizer提高gdi+绘图质量

使用OctreeQuantizer提高gdi+绘图质量

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23
   

.net中gdi+绘制的图形质量很少,原因是gdi+使用的是256色的。

为了提高绘制图片的质量,可以使用是“Octree“ 算法。“Octree“ 算法允许我们插入自己的算法来量子化我们的图像。 

  一个好的“颜色量子化”算法“应该考虑在两个像素颗粒之间填充与这两个像素颜色相近的过渡颜色,提供更多可视颜色空间。

  Morgan Skinner提供了很好的“Octree“ 算法代码,大家可以下载参考使用。

  使用OctreeQuantizer很方便:

     public byte[] Draw()
        {
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(this.imageWidth, this.imageHeight);
            Graphics g = Graphics.FromImage(image);
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            //绘制图片
            this.RenerImage(g);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            //使用octreequantizer清晰化图片
            OctreeQuantizer oqt = new OctreeQuantizer(255, 8);
            System.Drawing.Bitmap highImage = oqt.Quantize(image);
            highImage.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            byte[] buffer = ms.ToArray();
            g.Dispose();
            image.Dispose();
            highImage.Dispose();
            return buffer;
        }

                 

             
  • OctreeQuantizer.zip (6.6 KB)