private void Export_Click(object sender, EventArgs e) { SaveFileDialog fde = new SaveFileDialog(); fde.Filter = "CSV file(*.csv)|*.csv"; fde.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString(); fde.RestoreDirectory = true; if (fde.ShowDialog() == DialogResult.OK) { System.IO.StreamWriter file = new System.IO.StreamWriter(fde.FileName); ThermalImageFile th = new ThermalImageFile(filename); double[,] pixel_array = th.ImageProcessing.GetPixelsArray(); //array containing the raw signal data for (int y = 0; y < th.Height; y++) { string line = string.Empty; for (int x = 0; x < th.Width; x++) { int pixel_int = (int)pixel_array[y, x]; //casting the signal value to int double pixel_temp = th.GetValueFromSignal(pixel_int); //converting signal to temperature line += pixel_temp.ToString("0.00") + ";"; //"building" each line } file.WriteLine(line); //writing a line to the excel sheet } file.Flush(); file.Close(); th.Dispose(); } }
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) { if (_cam1 != null) { _cam1.ConnectionStatusChanged -= _cam1_ConnectionStatusChanged; _cam1.Disconnect(); } th.Dispose(); }
private void Open_Click(object sender, EventArgs e) { OpenFileDialog fd = new OpenFileDialog(); fd.Filter = "Image files (*.jpg)|*.jpg"; fd.InitialDirectory = Environment.SpecialFolder.MyPictures.ToString(); fd.RestoreDirectory = true; if (fd.ShowDialog() == DialogResult.OK) { filename = fd.FileName; ThermalImageFile th = new ThermalImageFile(filename); var img = th.Image; pictureBox1.Image = (Image)img.Clone(); th.Dispose(); } }
public static int Paljpgmake(string fname_a, string fname_b) { if (new DriveInfo(Directory.GetCurrentDirectory().Substring(0, 2)).TotalFreeSpace < 1073741824L) { return(2); } try { double num1 = 1000.0; double num2 = -1000.0; PaletteMake.jpgname = fname_b; PaletteMake.palname = fname_a; Palette palette = PaletteManager.Open(PaletteMake.palname); ThermalImageFile thermalImageFile = new ThermalImageFile(PaletteMake.jpgname); thermalImageFile.Fusion.Mode = (FusionMode)thermalImageFile.Fusion.VisualOnly; Bitmap image = thermalImageFile.Image; int width = thermalImageFile.Width; int height = thermalImageFile.Height; double num3 = 0.0; double num4 = 0.0; double[] numArray = new double[width * height]; double[,] pixelsArray = thermalImageFile.ImageProcessing.GetPixelsArray(); for (int index1 = 0; index1 < thermalImageFile.Height; ++index1) { string empty = string.Empty; for (int index2 = 0; index2 < thermalImageFile.Width; ++index2) { int signal = (int)pixelsArray[index1, index2]; double valueFromSignal = thermalImageFile.GetValueFromSignal(signal); numArray[width * index1 + index2] = valueFromSignal; num3 += valueFromSignal * valueFromSignal; num4 += valueFromSignal; if (num1 > numArray[width * index1 + index2]) { num1 = numArray[width * index1 + index2]; } if (num2 < numArray[width * index1 + index2]) { num2 = numArray[width * index1 + index2]; } } } int num5 = width * height; double num6 = Math.Sqrt((num3 - num4 * num4 / (double)num5) / (double)num5); double num7 = num4 / (double)num5; double num8 = num7 - num6 * 3.0; double num9 = num7 + num6 * 3.0; thermalImageFile.Dispose(); Bitmap bitmap = new Bitmap(width, height); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int index = numArray[width * y + x] >= num8 ? (numArray[width * y + x] <= num9 ? (int)((numArray[width * y + x] - num8) / (num9 - num8) * (double)byte.MaxValue) : (int)byte.MaxValue) : 0; Color paletteColor = palette.PaletteColors[index]; byte r = paletteColor.R; paletteColor = palette.PaletteColors[index]; byte g = paletteColor.G; paletteColor = palette.PaletteColors[index]; byte b = paletteColor.B; bitmap.SetPixel(x, y, Color.FromArgb((int)r, (int)g, (int)b)); } } string[] strArray1 = PaletteMake.jpgname.Split('.'); string[] strArray2 = PaletteMake.palname.Split('.')[0].Split('\\'); string filename = strArray1[0] + "_" + strArray2[strArray2.Length - 1] + ".jpg"; bitmap.Save(filename); return(0); } catch (Exception ex) { return(1); } }