示例#1
0
        public static void ImportImage(Altaxo.Data.DataTable table)
        {
            ColorAmplitudeFunction colorfunc;

            System.IO.Stream myStream;
            OpenFileDialog   openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "Image files (*.bmp;*.jpg;*.png,*.tif)|*.bmp;*.jpg;*.png,*.tif|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(myStream);

                    int sizex = bmp.Width;
                    int sizey = bmp.Height;
                    //if(Format16bppGrayScale==bmp.PixelFormat)

                    colorfunc = new ColorAmplitudeFunction(ColorToBrightness);
                    // add here other function or the result of a dialog box

                    // now add new columns to the worksheet,
                    // the name of the columns should preferabbly simply
                    // the index in x direction

                    table.Suspend();
                    for (int i = 0; i < sizex; i++)
                    {
                        Altaxo.Data.DoubleColumn dblcol = new Altaxo.Data.DoubleColumn();
                        for (int j = sizey - 1; j >= 0; j--)
                        {
                            dblcol[j] = colorfunc(bmp.GetPixel(i, j));
                        }

                        table.DataColumns.Add(dblcol, table.DataColumns.FindUniqueColumnName(i.ToString())); // Spalte hinzufügen
                    } // end for all x coordinaates

                    table.Resume();

                    myStream.Close();
                    myStream = null;
                } // end if myStream was != null
            }
        }
示例#2
0
        /// <summary>
        /// Asks for a file name of an image file, and imports the image data into a data table.
        /// </summary>
        /// <param name="table">The table to import to.</param>
        public static void ShowImportImageDialog(this DataTable table)
        {
            ColorAmplitudeFunction colorfunc;
            var options = new Altaxo.Gui.OpenFileOptions();

            options.AddFilter("*.bmp;*.jpg;*.png,*.tif", "Image files (*.bmp;*.jpg;*.png,*.tif)");
            options.AddFilter("*.*", "All files (*.*)");
            options.FilterIndex      = 0;
            options.RestoreDirectory = true;

            if (Current.Gui.ShowOpenFileDialog(options))
            {
                using (Stream myStream = new FileStream(options.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var bmp = new System.Drawing.Bitmap(myStream);

                    int sizex = bmp.Width;
                    int sizey = bmp.Height;
                    //if(Format16bppGrayScale==bmp.PixelFormat)

                    colorfunc = new ColorAmplitudeFunction(ColorToBrightness);
                    // add here other function or the result of a dialog box

                    // now add new columns to the worksheet,
                    // the name of the columns should preferabbly simply
                    // the index in x direction

                    using (var suspendToken = table.SuspendGetToken())
                    {
                        for (int i = 0; i < sizex; i++)
                        {
                            var dblcol = new Altaxo.Data.DoubleColumn();
                            for (int j = sizey - 1; j >= 0; j--)
                            {
                                dblcol[j] = colorfunc(bmp.GetPixel(i, j));
                            }

                            table.DataColumns.Add(dblcol, table.DataColumns.FindUniqueColumnName(i.ToString())); // Spalte hinzufügen
                        } // end for all x coordinaates

                        suspendToken.Dispose();
                    }
                    myStream.Close();
                } // end using myStream
            }
        }
示例#3
0
    public static void ImportImage(Altaxo.Data.DataTable table)
    {
      ColorAmplitudeFunction colorfunc;
      System.IO.Stream myStream;
      OpenFileDialog openFileDialog1 = new OpenFileDialog();

      openFileDialog1.InitialDirectory = "c:\\" ;
      openFileDialog1.Filter = "Image files (*.bmp;*.jpg;*.png,*.tif)|*.bmp;*.jpg;*.png,*.tif|All files (*.*)|*.*";
      openFileDialog1.FilterIndex = 1 ;
      openFileDialog1.RestoreDirectory = true ;

      if(openFileDialog1.ShowDialog() == DialogResult.OK)
      {
        if((myStream = openFileDialog1.OpenFile())!= null)
        {
          System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(myStream);

          int sizex = bmp.Width;
          int sizey = bmp.Height;
          //if(Format16bppGrayScale==bmp.PixelFormat)
          
          colorfunc = new ColorAmplitudeFunction(ColorToBrightness);
          // add here other function or the result of a dialog box
  
          // now add new columns to the worksheet, 
          // the name of the columns should preferabbly simply
          // the index in x direction

          table.Suspend();
          for(int i=0;i<sizex;i++)
          {
            Altaxo.Data.DoubleColumn dblcol = new Altaxo.Data.DoubleColumn();
            for(int j=sizey-1;j>=0;j--)
              dblcol[j] = colorfunc(bmp.GetPixel(i,j));

            table.DataColumns.Add(dblcol,table.DataColumns.FindUniqueColumnName(i.ToString())); // Spalte hinzufügen
          } // end for all x coordinaates

          table.Resume();

          myStream.Close();
          myStream=null;
        } // end if myStream was != null
      } 
    }
示例#4
0
		/// <summary>
		/// Asks for a file name of an image file, and imports the image data into a data table.
		/// </summary>
		/// <param name="table">The table to import to.</param>
		public static void ShowImportImageDialog(this DataTable table)
		{
			ColorAmplitudeFunction colorfunc;
			var options = new Altaxo.Gui.OpenFileOptions();
			options.AddFilter("*.bmp;*.jpg;*.png,*.tif", "Image files (*.bmp;*.jpg;*.png,*.tif)");
			options.AddFilter("*.*", "All files (*.*)");
			options.FilterIndex = 0;
			options.RestoreDirectory = true;

			if (Current.Gui.ShowOpenFileDialog(options))
			{
				using (Stream myStream = new FileStream(options.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(myStream);

					int sizex = bmp.Width;
					int sizey = bmp.Height;
					//if(Format16bppGrayScale==bmp.PixelFormat)

					colorfunc = new ColorAmplitudeFunction(ColorToBrightness);
					// add here other function or the result of a dialog box

					// now add new columns to the worksheet,
					// the name of the columns should preferabbly simply
					// the index in x direction

					using (var suspendToken = table.SuspendGetToken())
					{
						for (int i = 0; i < sizex; i++)
						{
							Altaxo.Data.DoubleColumn dblcol = new Altaxo.Data.DoubleColumn();
							for (int j = sizey - 1; j >= 0; j--)
								dblcol[j] = colorfunc(bmp.GetPixel(i, j));

							table.DataColumns.Add(dblcol, table.DataColumns.FindUniqueColumnName(i.ToString())); // Spalte hinzufügen
						} // end for all x coordinaates

						suspendToken.Dispose();
					}
					myStream.Close();
				} // end using myStream
			}
		}