前文可以参考我的前一篇博文:c# .net实现简易灰度图和酷炫heatmap热力图winform
但是,先前的热力图效果,我并不满意。不满意的地方主要有三点:
热力图的颜色是通过一个调色板图片来实现,如果想要其他颜色,改起来比较麻烦热力图的扩散效果不好看,不够渐进热力图的每个点大小都一致,应该是大小不一才对因此,我做了改进,上一个图是之前的效果,下一个图是改进后的效果
//创建调色板,颜色映射private colormap[] createpalette(){ colormap[] colormaps = new colormap[256]; list<color> newcolors = new list<color>(); //颜色集合 newcolors.addrange(getgradientcolorlist(color.red, color.yellow, 64)); newcolors.addrange(getgradientcolorlist(color.yellow, color.green, 64)); newcolors.addrange(getgradientcolorlist(color.green, color.blue, 64)); newcolors.addrange(getgradientcolorlist(color.blue, color.navy, 64)); //颜色调色板展示 bitmap colorbitmap = new bitmap(colorpanel.width, colorpanel.height); graphics graphic = graphics.fromimage(colorbitmap); for (int i = 0; i < 256; i++) { solidbrush solidbrush = new solidbrush(newcolors[i]); rectangle rectangle = new rectangl内能与什么因素有关e((int)(i * 2), 0, (int)2, colorpanel.height); graphic.fillrectangle(solidbrush, rectangle); graphic.save(); solidbrush.dispo(); } colorpanel.backgroundimage = colorbitmap; // 遍历每个像素并创建一个新的颜色映射 for (int x = 0; x <= 255; x++) { colormaps[x] = new colormap(); colormaps[x].oldcolor = system.drawing.color.fromargb(x, x, x); colormaps[x].newcolor = system.drawing.color.fromargb(255, newcolors[x]); } return colormaps;}/// <summary>/// 获得两个颜色之间渐进颜色的集合/// </summary>/// <param name="sourcecolor">起始颜色</param>/// <param name="destcolor">终止颜色</param>/// <param name="count">渐进颜色的个数</param>家访内容怎么写;/// <returns>返回颜色集合</returns>public static list<color> getgradientcolorlist(color srccolor, color descolor, int count){ list<color> colorfactorlist = new list<color>(); int redspan = descolor.r - srccolor.r; int greenspan = descolor.g - srccolor.g; int bl姜夔 扬州慢uespan = descolor.b - srccolor.b; for (int i = 0; i < count; i++) { color color = color.fromargb( srccolor.r + (int)((double)i / count * redspan), srccolor.g + (int)((double)i / count * greenspan), srccolor.b + (int)((double)i / count * bluespan) ); colorfactorlist.add(color); } return colorfactorlist;}
private void drawheatpoint2(graphics graphics, heatpoint heatpoint){ console.writeline("heatpoint.intensity = " + heatpoint.intensity); int radius = 40 * (heatpoint.intensity+6) / 240; list<system.drawing.point> pointslist = new list<system.drawing.point>(); for (double degrees = 0; degrees <= 360; degrees += 10) { // 在定义半径的圆的圆周上绘制新点 // 使用点坐标、半径和角度 // 计算这个迭代点在圆上亲子游戏大全的位置 system.drawing.point point = new system.drawing.point(); point.x = convert.toint32(heatpoint.x + radius * math.cos((math.pi / 180) * degrees)); point.y = convert.toint32(heatpoint.y + radius * math.sin((math.pi / 180) * degrees)); pointslist.add(point); } // 创建新的颜色混合来告诉 pathgradientbrush 使用什么颜色以及放置它们的位置 colorblend colorblend = new colorblend(3); colorblend.positions = new float[3] { 0, 0.8f, 1 }; colorblend.colors = new system.drawing.color[3] { system.drawing.color.fromargb(0, system.drawing.color.white), system.drawing.color.fromargb(heatpoint.intensity, system.drawing.color.black), system.drawing.color.fromargb(heatpoint.intensity, system.drawing.color.black) }; // 创建新的 pathgradientbrush 以使用圆周点创建径向渐变 pathgradientbrush brush = new pathgradientbrush(pointslist.toarray()); // 将颜色混合传递给 pathgradientbrush 以指示它如何生成渐变 brush.interpolationcolors = colorblend; graphics.fillpolygon(brush, pointslist.toarray()); //brush.dispo();}
四、更新视图
private void updateview(){ //灰度 bitmap bitmap1 = createintensitymask(new bitmap((int)panel1.width, (int)panel1.height, system.drawing.imaging.pixelformat.format32bppargb), heatpoints, 1); panel1.backgroundimage = bitmap1; //上色 panel3.backgroundimage = colorize(bitmap1);}private bitmap createintensitymask(bitmap bitmap, list<heatpoint> aheatpoints){ //从bitmap获得graphics gdi+ 绘图图面 graphics 肖的组词graphics = graphics.fromimage(bitmap); //清除整个绘图面并以白色填充 graphics.clear(system.drawing.color.white); foreach (heatpoint point in aheatpoints) { drawheatpoint2(graphics, point); } return bitmap;}
到此这篇关于c# .net实现灰度图和heatmap热力图winform(进阶)的文章就介绍到这了,更多相关c# .net 灰度图 热力图内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
本文发布于:2023-04-04 03:19:12,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/4a8c4e4f1d2ebc64c319e43a4f617621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:C# .Net实现灰度图和HeatMap热力图winform(进阶).doc
本文 PDF 下载地址:C# .Net实现灰度图和HeatMap热力图winform(进阶).pdf
留言与评论(共有 0 条评论) |