Add a declaration:
Image myImage = panel1.BackgroundImage;
And put it after your
if
condition (or expand the
if
to encompass the remaining code - you only want to execute it if the user presses "OK" after all. I would also recommend that your OpenFileDialog is constructed in the method, and you use a Bitmap as the generic Image does not have a GetPixel method.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "JPEG IMAGES|*.jpg";
openFileDialog1.InitialDirectory = "C:\\Users\\jason\\Documents\\IProject\\code\\imageAlign\\imageAlign\\bin\\Debug";
openFileDialog1.Title = "Open Image";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Bitmap myImage = (Bitmap)Image.FromFile(openFileDialog1.FileName);
panel1.BackgroundImage = myImage;
panel1.Invalidate();
float[] resultArray = new float[myImage.Height];
for (int i = 0; i < myImage.Height; i++)
{
float value = 0;
for (int j = 0; j < myImage.Width; j++)
{
value += myImage.GetPixel(j, i).GetBrightness();
}
resultArray[i] = value;
}
}