基本信息
源码名称:C#简单实现热度图
源码大小:5.00M
文件格式:.zip
开发语言:C#
更新时间:2019-04-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
采用GDI 简单实现热度图
采用GDI 简单实现热度图
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HeatMap;
using TestHeatMap.Properties;
namespace TestHeatMap
{
public partial class Form1 : Form
{
int _width;
int _height;
int _count;
float _opacity;
int _radius;
ColorRamp _colorRamp;
List<HeatPoint> _points;
public Form1()
{
InitializeComponent();
}
List<HeatPoint> randomPoints(int width, int height, int count)
{
var result = new List<HeatPoint>();
var r = new Random();
for (int i = 0; i < count; i )
{
var x = r.Next(width);
var y = r.Next(height);
//var w = (float)r.NextDouble()/2;
var point = new HeatPoint
{
X = x,
Y = y,
W = 1
};
result.Add(point);
}
return result;
}
private async void make4Maps(int width, int height, int radius, List<HeatPoint> points, float opacity, ColorRamp cr)
{
var hmMaker = new HeatMapMaker
{
Width = width,
Height = height,
Radius = radius,
ColorRamp = cr,
HeatPoints = points,
Opacity = opacity
};
this.pictureBox2.BackgroundImage = await hmMaker.MakeHeatMap();
//
this.pictureBox1.BackgroundImage = hmMaker.GrayMap;
//
displayInfo();
}
private void displayInfo()
{
this.lblCount.Text = String.Format("{0}:{1}", "点数", _count);
this.lblRadius.Text = String.Format("{0}:{1}", "半径", _radius);
this.lblOpacity.Text = String.Format("{0}:{1}", "透明度", _opacity);
}
private void tbHPCount_Scroll(object sender, EventArgs e)
{
_count = this.tbHPCount.Value;
_points = randomPoints(_width, _height, _count);
make4Maps(_width, _height, _radius, _points, _opacity, _colorRamp);
}
private void tbHPRadius_Scroll(object sender, EventArgs e)
{
_radius = this.tbHPRadius.Value;
make4Maps(_width, _height, _radius, _points, _opacity, _colorRamp);
}
private void tbOpacity_Scroll(object sender, EventArgs e)
{
_opacity = this.tbOpacity.Value/10f;
make4Maps(_width, _height, _radius, _points, _opacity, _colorRamp);
}
private void cmbColorRamp_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.cmbColorRamp.SelectedIndex)
{
case 0:
this.pictureBox3.BackgroundImage = Resources.i_thermal;
break;
case 1:
this.pictureBox3.BackgroundImage = Resources.i_rainbow;
break;
case 2:
this.pictureBox3.BackgroundImage = Resources.i_redwhiteblue;
break;
}
_colorRamp = (ColorRamp)Enum.Parse(typeof(ColorRamp), this.cmbColorRamp.SelectedItem.ToString());
make4Maps(_width, _height, _radius, _points, _opacity, _colorRamp);
}
private void Form1_Load(object sender, EventArgs e)
{
_width = this.pictureBox1.Width;
_height = this.pictureBox1.Height;
_opacity = this.tbOpacity.Value / 10f;
_count = this.tbHPCount.Value;
_radius = this.tbHPRadius.Value;
_points = randomPoints(_width, _height, _count);
this.cmbColorRamp.SelectedIndex = 1;
_colorRamp = (ColorRamp)Enum.Parse(typeof(ColorRamp), this.cmbColorRamp.SelectedItem.ToString());
make4Maps(_width, _height, _radius, _points, _opacity, _colorRamp);
}
}
}