📄 form1.cs
字号:
Bitmap ironpal = new Bitmap(pictureBox2.Width, pictureBox2.Height); //pictureBox2.Height=256
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < pictureBox2.Width; j++)
{
ironpal.SetPixel(j, i, Color.FromArgb(irontable[255 - i, 0], irontable[255 - i, 1], irontable[255 - i, 2]));
}
}
pictureBox2.Image = ironpal;
///////////////////////////////////////////////////////数据的处理
for (int i = 0; i < temtable.table.Length; i = i + 1)
{
int t = (int)((temtable.table[i] - min) * 1.0 / (max - min) * 256);
if (t >= 255)
t = 255;
else if (t < 0)
t = 0;
rgbvalue[3 * i] =(byte)irontable [t,2]; //bmp图像颜色顺序是BGR而不是调色板的顺序RGB
rgbvalue[3 * i + 1] = (byte)irontable [t,1];
rgbvalue[3 * i + 2] =(byte)irontable [t,0];
}
break;
case "热金属10": //基于热金属10伪彩编码的显示
///////////////////////////////////////////////////热金属10调色板颜色的显示,将调色板100-124索引剔除取0,25,50,75,125,150,175,200,225,250十个代表
Bitmap iron10pal = new Bitmap(pictureBox2.Width, pictureBox2.Height); //pictureBox2.Height=256
for (int i =0; i<250; i++)
{
for (int j =0; j<pictureBox2.Width ; j++)
{
if (i / 25 <6)
{
iron10pal.SetPixel(j, i, Color.FromArgb(irontable[250 - i / 25 * 25, 0], irontable[250 - i / 25 * 25, 1], irontable[250 - i / 25 * 25, 2]));
}
else
{
iron10pal.SetPixel(j, i, Color.FromArgb(irontable[225 - i / 25 * 25, 0], irontable[225 - i / 25 * 25, 1], irontable[225 - i / 25 * 25, 2]));
}
}
}
pictureBox2.Image = iron10pal;
///////////////////////////////////////////////////////数据的处理
for (int i = 0; i < temtable.table.Length; i = i + 1)
{
int t = (int)((temtable.table[i] - min) * 1.0 / (max - min) * 256);
if (t >= 249)
t = 249;
else if (t < 0)
t = 0;
if (t / 25 < 4)
{
rgbvalue[3 * i] = (byte)irontable[t / 25 * 25, 2]; //bmp图像颜色顺序是BGR而不是调色板的顺序RGB
rgbvalue[3 * i + 1] = (byte)irontable[t / 25 * 25, 1];
rgbvalue[3 * i + 2] = (byte)irontable[t / 25 * 25, 0];
}
else
{
rgbvalue[3 * i] = (byte)irontable[t / 25 * 25 + 25, 2];
rgbvalue[3 * i + 1] = (byte)irontable[t / 25 * 25+ 25, 1];
rgbvalue[3 * i + 2] = (byte)irontable[t / 25 * 25 + 25, 0];
}
}
break;
case "彩虹": //基于彩虹伪彩编码的显示
RainTable raintable = new RainTable();
///////////////////////////////////////////////////彩虹调色板颜色的显示
Bitmap rainpal = new Bitmap(pictureBox2.Width, pictureBox2.Height); //pictureBox2.Height=256
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < pictureBox2.Width; j++)
{
rainpal.SetPixel(j, i, Color.FromArgb(raintable.table[255 - i, 0], raintable.table[255 - i, 1], raintable.table[255 - i, 2]));
}
}
pictureBox2.Image = rainpal;
///////////////////////////////////////////////////////数据的处理
for (int i = 0; i < temtable.table.Length; i = i + 1)
{
int t = (int)((temtable.table[i] - min) * 1.0 / (max - min) * 256);
if (t >= 255)
t = 255;
else if (t < 0)
t = 0;
rgbvalue[3 * i] = (byte)raintable.table[t, 2]; //bmp图像颜色顺序是BGR而不是调色板的顺序RGB
rgbvalue[3 * i + 1] = (byte)raintable.table[t, 1];
rgbvalue[3 * i + 2] = (byte)raintable.table[t, 0];
}
break;
case "彩虹10": //基于彩虹10伪彩编码的显示
RainTable raintable10 = new RainTable();
///////////////////////////////////////////////////彩虹10调色板颜色的显示
Bitmap rain10pal = new Bitmap(pictureBox2.Width, pictureBox2.Height); //pictureBox2.Height=256
for (int i = 0; i < 250; i++)
{
for (int j = 0; j < pictureBox2.Width; j++)
{
if (i / 25 < 3)
{
rain10pal.SetPixel(j, i, Color.FromArgb(raintable10.table[250 - i / 25 * 25, 0], raintable10.table[250 - i / 25 * 25, 1], raintable10.table[250 - i / 25 * 25, 2]));
}
else
{
rain10pal.SetPixel(j, i, Color.FromArgb(raintable10.table[225 - i / 25 * 25, 0], raintable10.table[225 - i / 25 * 25, 1], raintable10.table[225 - i / 25 * 25, 2]));
}
}
}
pictureBox2.Image = rain10pal;
///////////////////////////////////////////////////////数据的处理
for (int i = 0; i < temtable.table.Length; i = i + 1)
{
int t = (int)((temtable.table[i] - min) * 1.0 / (max - min) * 256);
if (t >= 249)
t = 249;
else if (t < 0)
t = 0;
if (t / 25 < 7)
{
rgbvalue[3 * i] = (byte)raintable10.table[t / 25 * 25, 2]; //bmp图像颜色顺序是BGR而不是调色板的顺序RGB
rgbvalue[3 * i + 1] = (byte)raintable10.table[t / 25 * 25, 1];
rgbvalue[3 * i + 2] = (byte)raintable10.table[t / 25 * 25, 0];
}
else
{
rgbvalue[3 * i] = (byte)raintable10.table[t / 25 * 25+25, 2];
rgbvalue[3 * i + 1] = (byte)raintable10.table[t / 25 * 25+25, 1];
rgbvalue[3 * i + 2] = (byte)raintable10.table[t / 25 * 25+25, 0];
}
}
break;
}//switch end
Marshal.Copy(rgbvalue, 0, ptr, bytes); //处理后的图像数据复制到内存
Mybitmap.UnlockBits(bmdata); //内存解锁
this.pictureBox1.Image = Mybitmap; //图像显示
pictureBox1.Refresh();
}
///////////////////////////////////////////////////////////////////////////////////////////////////读温度的一个临时控件
private void button3_Click(object sender, EventArgs e) //用饱和度模拟温度的值y=.299*R+0.587*G+0.114*B
{
Bitmap Mybitmap = (Bitmap)this.pictureBox1.Image; //要处理的图像
int bytes = Mybitmap.Width * Mybitmap.Height * 3; //数据数目
byte[] rgbvalue = new byte[bytes]; //存放原始图像的颜色值320*240*3
Rectangle rect = new Rectangle(pictureBox1.Location, pictureBox1.Size);
BitmapData bmdata = Mybitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); //图像颜色锁入内存
IntPtr ptr = bmdata.Scan0; //图像首行地址
Marshal.Copy(ptr, rgbvalue, 0, bytes); //图像颜色值复制到处理数组
for (int i = 0, j = 0; i < rgbvalue.Length; i = i + 3, j = j + 1)
{
temtable.table[j] = (byte)(rgbvalue[i] * 0.114 + rgbvalue[i + 1] * 0.587 + rgbvalue[i + 2] * 0.299);
}
Marshal.Copy(rgbvalue, 0, ptr, bytes);
Mybitmap.UnlockBits(bmdata);
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
//if (trackBar1.Value < trackBar2.Value)
// trackBar2.Value = trackBar1.Value - 1;
float f = (max - min) / 100; //trackBar1.Maximum设定为100,max,min 为图像的最值,全局变量,前面已定义并求出
float tmax = (trackBar1.Value-50) * f+max;
label2.Text = tmax.ToString(); //温度下上限的显示
float tmin = (trackBar2.Value-50) * f+min ;
label3.Text = tmin.ToString(); //温度下限的显示
label4.Text = "温度上限:" + label2.Text;
label5.Text = "温度下限:" + label3.Text;
//////////////////////////////////////////////////////////////////////////////////////////////////
Bitmap Mybitmap = (Bitmap)this.pictureBox1.Image; //要处理的图像
int bytes = Mybitmap.Width * Mybitmap.Height * 3; //数据数目
byte[] rgbvalue = new byte[bytes]; //存放原始图像的颜色值320*240*3
Rectangle rect = new Rectangle(pictureBox1.Location, pictureBox1.Size);
BitmapData bmdata = Mybitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); //图像颜色锁入内存
IntPtr ptr = bmdata.Scan0; //图像首行地址
Marshal.Copy(ptr, rgbvalue, 0, bytes); //图像颜色值复制到处理数组
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string pal = comboBox1.Text;
switch (pal) //根据温度上下限重新绘图,tmax对应最亮的颜色,tmin最暗色
{
case "灰度": // grey
for (int i = 0; i < temtable.table.Length; i++)
{
int t=(int)((temtable .table [i] -tmin)/(tmax -tmin )*256);
if (t >255)
t = 255;
else if (t < 0)
t = 0;
rgbvalue[3 * i] =(byte ) t;
rgbvalue[3 * i+ 1] = (byte)t;
rgbvalue[3 * i+2] = (byte)t;
}
break;
case "逆灰度": //congrey
for (int i = 0; i < temtable.table.Length; i++)
{
int t = (int)((temtable.table[i] - tmin) / (tmax - tmin) * 256);
if (t > 255)
t = 255;
else if (t < 0)
t = 0;
rgbvalue[3 * i] = (byte)(255 - t);
rgbvalue[3 * i+1] = (byte)(255 - t);
rgbvalue[3 * i+2] = (byte)(255 - t);
}
break;
case "黄色": // yellow
for (int i = 0; i < temtable.table.Length; i++)
{
int t = (int)((temtable.table[i] - tmin) / (tmax - tmin) * 256);
if (t > 255)
t = 255;
else if (t < 0)
t = 0;
rgbvalue[3 * i] = 0; //bmp图像颜色顺序是BGR而不是调色板的顺序RGB
rgbvalue[3 * i+ 1] = (byte)t;
rgbvalue[3 * i+ 2] = (byte)t;
}
break;
case "热金属": //iron
for (int i = 0; i < temtable.table.Length; i++)
{
int t = (int)((temtable.table[i] - tmin) / (tmax - tmin) * 256);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -