热力点类
class heatpoint { public int x; public int y; public byte intensity; public heatpoint(in求同存异英文t ix, int iy, byte bintensity) { x = ix; y = iy; intensity = bintensity; } }
随机生成热力点
privatevoid generatebtn_click(object nder, eventargs e){ random rrand = new random(); for (int i = 0; i < 500; i++) { int ix = rrand.next(0, 800); int iy = rrand.next(0, 800); byte iinten = (byte)rrand.next(0, 180); heatpoints.add(new heatpoint(ix, iy, i国庆假期的作文inten)); } updateview();}
private bitmap createintensitymask(bitmap bitmap, list<heatpoint> aheatpoints){ graphics graphics = graphics.fromimage(bitmap); graphics.clear(system.drawing.color.white); foreach (heatpoint point in aheatpoints) { if (point.intensity * 30 / 180 == 0) continue; drawheatpoint(graphics, point, point.intensity * 30 / 180); //drawheatpoint(graphics, point, 15); } return bitmap;}//此方法用于在绘图表面上绘制实际的径向渐变“点”。这可能是整个项目中最重要的方法,因为它可以处理不同大小和密度的绘图点。private void drawheatpoint(graphics graphics, heatpoint heatpoint, int radius){ 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); // 计算比例以将字节强度范围从 0-255 缩放到 0-1 float fratio = 1f / byte.maxvalue; /网络与新媒体专业/ 预计算字节最大值的一半 byte bhalf = byte.maxvalue / 2; // 将其中心值的强度从低高翻转到高低 int iintensity = (byte)(heatpoint.intensity - ((heatpoint.intensity - bhalf) * 2)); // 存储缩放和翻转的强度值以用于梯度中心位置 float fintensity = iintensity * fratio; // 定义渐变颜色的位置,使用intesity将中间颜色调整为 colorblend.positions = new float[3] { 0, fintensity, 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());}
public sta最佳损友歌词tic bitmap colorize(bitmap mask, byte alpha){ bitmap output = new bitmap(mask.width, mask.height, system.drawing.imaging.pixelformat.format32bppargb); graphics surface = graphics.fromimage(output); surface.clear(system.drawing.color.transparent); // 构建一组颜色映射以将我们的灰度蒙版重新映射为全色 // 接受一个 alpha 字节来指定输出图像的透明度 colormap[] colors = createpaletteindex(alpha); // 创建新的图像属性类来处理颜色重新映射 // 注入我们的颜色映射数组来指示图像属性类如何进行着色 imageattributes remapper = new imageattributes(); remapper.tremaptable(colors); // 使用新的颜色映射方案将我们的蒙版绘制到我们的内存位图工作表面上 surface.drawimage(mask, new system.drawing.rectangle(0, 0, m青春的秘密ask.width, mask.height), 0, 0, mask.width, mask.height, graphicsunit.pixel, remapper); return output;}private static colormap[] createpaletteindex(byte alpha){ colormap[] outputmap = new colormap[256]; asmbly myasmbly = asmbly.getexecutingasmbly(); stream mystream = myasmbly.getmanifestresourcestream("热力图demo.image.gradient-palette.jpg"); bitmap palette = new bitmap(mystream); for (int x = 0; x <= 255; x++) { outputmap[x] = new colormap(); outputmap[x].oldcolor = system.drawing.color.fromargb(x, x, x); outputmap[x].newcolor = system.drawing.color.fromargb(alpha, palette.getpixel(x, 0)); } return outputmap;}
热力图demo.zip
到此这篇关于c#实现简易灰度图和酷炫heatmap热力图winform(附demo)的文章就介绍到这了,更多相关c# 灰度图和热力图内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
本文发布于:2023-04-04 02:04:37,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/d0684c2441e611800d3953ef6e5f062d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:C#实现简易灰度图和酷炫HeatMap热力图winform(附DEMO).doc
本文 PDF 下载地址:C#实现简易灰度图和酷炫HeatMap热力图winform(附DEMO).pdf
留言与评论(共有 0 条评论) |