Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to read the pixels value on a line in an image:
C#
byte[] myArray=new byte[20];
for(int i=0;i<20;i++)
    myArray[i]=0;

myImage.GetLine(ref myArray, 10,10,20,10);


Getline is the function provided by myImage, which has 5 parameters:
ref object, int startX,int startY, int endX,int EndY;

When run the above code, it will show error as: cannot convert 'ref byte[]' to 'ref object'.

But when I call it in this way:
C#
object points=null;
myImage.GetLine(ref points,10,10,20,10);
The error will show as: invalid userarray.


Don't know why?
Posted

You cannot call the method with a ref parameter to any type other than exactly the parameter type specified. The reasoning is pretty simple - suppose you could:

C#
private void MyMethod(ref object o)
   {
   o = (object) new Point(10, 10);
   }
...
   byte[] data = new byte[1024];
   MyMethod(ref data);
   Console.WriteLine(data[100]);
What kind of output would you get? Apart from random and rubbish?

In order to call a method with a ref parameter, it must be an assignable value, so try
C#
byte[] myArray=new byte[20];
for(int i=0;i<20;i++)
    myArray[i]=0;
object o = myArray;
myImage.GetLine(ref o, 10,10,20,10);
The method can then change the value of o without affecting the array in any way.
 
Share this answer
 
Seems it will need a cast from myArray to Object.
What I want to get is to get a pixel's value when mouse moved on an image.

Thank you. I will try this later.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900