0

I am trying to open and read the pixel values for two separate images on the same form in c#. I get an error reading the following:

Error 1 Type 'imageAlign.Form1' already defines a member called 'GetPixels' with the same parameter types C:\Users\jason\Documents\Visual Studio 2010\Projects\imageAlign\imageAlign\Form1.cs 81 26 imageAlign

I think this means that I have two methods with the same name - GetPixels.

If this is just a name, can I just rename them to solve the problem - it won't affect the GetPixel functionality?

private Color[,] GetPixels1(string filename)
private Color[,] GetPixels2(string filename)

Like that?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • just curious, what's the difference in implementation of the methods? – bas Feb 10 '13 at 11:20
  • Nothing. They are both to get the pixel values in images but for two different images – Jason Moore Feb 10 '13 at 12:39
  • if the methods are identical, why would you declare a duplicate method? just call the same method twice, once with image1 and once with image2 as parameter. If I misunderstand what you are saying: my sincere apologies. Feel free to drop some more code in your question to clarify – bas Feb 10 '13 at 12:42

2 Answers2

0

It means that you already have method with same name and same parameters. You have to either rename your methods to reflect their purpose or overload method (by changing parameters).

It seems that those methods are doing almost same thing (thus same name and parameters), so, I suggest to refactor them, but in different way than just renaming them to GetPixel1 and GetPixel2.

Zbigniew
  • 27,184
  • 6
  • 59
  • 66
0

I would just use two different namespaces for this two classes and NOT try to rename the methods - therefor are the namespases finally ... Looks like

myFirstNamecpace.GetPixels(..)
mySecondNamespace.GetPixels(...)

[EDITED - Question of OP]

continuing with GetPixels - I would like to get the pixel values of a jpeg image and sum them up into one integer value. But a jpeg image has Red, Green and Blue channels, right? I have opened it in picture box as a Bitmap. So, would I need to loop through all 3 channels of each pixel or just get a single value of each pixel?

private Color[,] GetPixels_1(string filename) 
{ 
  Bitmap myImage1 = (Bitmap)pictureBox1.Image; 
  //Bitmap bmp = (Bitmap)Bitmap.FromFile(filename); 
  Color[,] results = new Color[myImage1.Width, myImage1.Height]; 
  for (int y = 0; y < myImage1.Height; y++) 
  { 
    for (int x = 0; x < myImage1.Width; x++) 
    { 
      results[x, y] = myImage1.GetPixel(x, y); 
    } 
  } 
  return results; 
}

[EDITED - Answer] To paste the code use {} of editor above. So, I have found this one, HTH:https://stackoverflow.com/a/10128284/1758762

using System.Drawing;

Bitmap img = new Bitmap("*imagePath*");
for (int i = 0; i < img.GetWidth; i++)
{
    for (int i = 0; i < img.GetWidth; i++)
    {
        Color pixel = img.GetPixel(i,j);

        if (pixel == *somecondition*)
        {
            **Store pixel here in a array or list or whatever** 
        }
    }
} 
Community
  • 1
  • 1
Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
  • continuing with GetPixels - I would like to get the pixel values of a jpeg image and sum them up into one integer value. But a jpeg image has Red, Green and Blue channels, right? I have opened it in picture box as a Bitmap. So, would I need to loop through all 3 channels of each pixel or just get a single value of each pixel? – Jason Moore Feb 10 '13 at 12:46
  • [code] private Color[,] GetPixels_1(string filename) { Bitmap myImage1 = (Bitmap)pictureBox1.Image; //Bitmap bmp = (Bitmap)Bitmap.FromFile(filename); Color[,] results = new Color[myImage1.Width, myImage1.Height]; for (int y = 0; y < myImage1.Height; y++) { for (int x = 0; x < myImage1.Width; x++) { results[x, y] = myImage1.GetPixel(x, y); } } return results; }[/code] – Jason Moore Feb 10 '13 at 12:46
  • anyone know how I can post code here? I tried 'code' '/code' and these [] but no joy – Jason Moore Feb 10 '13 at 12:52