首页 > 代码库 > 如何做一个伪彩色图
如何做一个伪彩色图
添加一个panel先
private void panel7_Paint(object sender, PaintEventArgs e) { //LinearGradientBrush brush = new LinearGradientBrush(e.ClipRectangle, Color.Green, Color.Blue, LinearGradientMode.Vertical); //e.Graphics.FillRectangle(brush, e.ClipRectangle); }
或者
public partial class Form1 : Form{ public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { const int samples = 100; int height = 60; int width = this.ClientRectangle.Width / samples; for (int i = 0; i < samples; i++) { Color color = FromScale((double)i / samples); Rectangle rect = new Rectangle(width * i, 0, width, height); using (Brush brush = new SolidBrush(color)) { e.Graphics.FillRectangle(brush, rect); } } } static Color[] colors = { Color.Blue, Color.Cyan, Color.Yellow, Color.Red }; static Color FromScale(double value) { if (value < 0 || value > 1) throw new ArgumentException("value must be in [0~1]"); value *= (colors.Length - 1); int section = Math.Min((int)Math.Floor(value), colors.Length - 2); double t = value - section; Color c1 = colors[section], c2 = colors[section + 1]; return Color.FromArgb( Interpolate(t, c1.R, c2.R), Interpolate(t, c1.G, c2.G), Interpolate(t, c1.B, c2.B) ); } static int Interpolate(double t, int i, int j) { int value = http://www.mamicode.com/(int)(i * (1 - t) + j * t);>
如何做一个伪彩色图
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。