-1

I'm new to programming, and everything what i done until now was research and implementing to fit my needs...

Currently I'm creating dataTable like this :

private void GridOfBitmaps()
        {
            Bitmap OriginBitmap = new Bitmap(pictureBox1.Image);
            DataTable LightnessTable = new DataTable("Lightness");

            for (int x = 0; x < pictureBox1.Width-20; x+= 20)
            {
                LightnessTable.Columns.Add("C" + x, typeof(string));
                for (int y = 0; y < pictureBox1.Height-20; y += 20)
                {
                    RectangleF smallRect = new RectangleF(x, y, 20, 20);
                    System.Drawing.Imaging.PixelFormat format =
                        OriginBitmap.PixelFormat;
                    Bitmap cloneBitmap = OriginBitmap.Clone(smallRect, format);
                    string avgLightness = Convert.ToString(CalculateAverageLightness(cloneBitmap));

                    int index = avgLightness.IndexOf(",");
                    if (index > 0)
                        avgLightness = avgLightness.Substring(0, index);

                    if (x <= 0)
                    {
                        DataRow row = LightnessTable.NewRow();
                        row["C" + x] = avgLightness;
                        LightnessTable.Rows.Add(row);
                    }
                    else
                    {
                        LightnessTable.Rows[y / 20]["C" + x] = avgLightness;
                    }
                }
            }

This function is signed to button, so on everyclick I'm geting new datatable.

DataTable rows holds values in range from 0 to 255 (string), i would like to be able to compare 2 datatables created in that way (cell by cell to determine if value is higher).

EDIT#: Question : How to store those datatables during program running so i can compare them later?

I can't use database. Thank You !

Kuba Do
  • 155
  • 9
  • https://stackoverflow.com/questions/9022118/access-cell-value-of-datatable You need to access each cell and compare it. – Louis Go Mar 18 '20 at 14:32
  • I think i wrongly asked... I will edit question – Kuba Do Mar 18 '20 at 14:34
  • It'll be better if you put two sample datatable data and describe what output you want. – Louis Go Mar 18 '20 at 14:35
  • Thanks Luis, i just updated. Its about storing dataTables for later use. I dont know how to do it without database – Kuba Do Mar 18 '20 at 14:37
  • Do you want to pass your `LightnessTable` out? Is there anything preventing you from changing `void GridOfBitmaps()` to `DataTable GridOfBitmaps()`? You may get this datatable after function is call. Eg `DataTable first = GridOfBitmaps()`. – Louis Go Mar 18 '20 at 14:39
  • Im not sure how i will use it, let say i will call this function 2 times, how to compare those datatables later ? Second click will overwrite first one ? – Kuba Do Mar 18 '20 at 14:44
  • Is your question "How to save two datatable results from a function call"? If yes, there are many ways. I'll write an answer to it. – Louis Go Mar 18 '20 at 14:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/209856/discussion-between-kuba-do-and-louis-go). – Kuba Do Mar 18 '20 at 14:52

1 Answers1

0
  1. You have one function.
  2. You need to save two or more result of after this function called multiple times.

Most general way is saving them in your private member.

First of all, change your signature to DataTable GridOfBitmaps()

DataTable GridOfBitmaps()
{
    Bitmap OriginBitmap = new Bitmap(pictureBox1.Image);
    DataTable LightnessTable = new DataTable("Lightness");

    // Your implementation here, omitted

    return LightnessTable;
}

Second, after you call the function, save it in your member variable

public partial class YourFormClass : Form
{
    List<DataTable> m_results = new List<DataTable>();
    void button_Click( object sender, EventArgs e )
    {
         DataTable result = GridOfBitmaps();
         m_results.Add( result );
    }
}

After two or more click, you need to press compare button to compare

void buttonCompare_Click( object sender, EventArgs e )
    {
         if( m_results.Count < 2 ){
             return;
         }
         DataTable first = m_results[ 0 ];
         DataTable second = m_results[ 1 ];
         // compare implementation.

         // compare finished. clear your results.
         m_results.Clear();
    }
Louis Go
  • 2,213
  • 2
  • 16
  • 29