Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,I want to pass few images as arguments but when done,all the images get the same value.here is some of my codes.please help me,thanks in advance
MIDL
Bitmap[] ima = new Bitmap[20];
           ima[0] = new Bitmap(Main_P.Image);
           ima[1] = gray(ima[0]);//Setting the picture trough gray scale
           ima[2] = noise(ima[1]);
           ima[3] = histogram(ima[2]);
           ima[4] = binary(ima[3]);
           ima[5] = reverse_binary(ima[4]);
           ima[6] = distance2(ima[5]);
           ima[7] = max2(ima[6]);
           ima[8] = extension_binary(ima[7]);
           ima[9] = complementary_0f_distance(ima[6]);
           ima[10] = apply_sign_image_to_basis_image(ima[9], ima[8], ima[5]);




          Main_P.Image =(Bitmap)ima[7];

here all the images get the same value!
Posted

It is likely that your issues aren't in how you pass the images as arguments, but rather what you do with them in the functions you are sending them to. Remember that arguments are being sent as references so that anything you do to manipulate the argument will affect all references to it.
 
Share this answer
 
Comments
ready to learn 30-Jun-11 10:34am    
do you mean that if I want to pass the bitmap it will be passed by refrence?notice that I didn't use "Ref".
fjdiewornncalwe 30-Jun-11 23:03pm    
It is important to know that in C#, objects are passed by reference whether you specify the ref keyword or not on them.
Sergey Alexandrovich Kryukov 1-Jul-11 23:40pm    
My 5. It looks like OP needs to learn a fundamental idea: reference types vs value types and their implications.
--SA
Is it possible that these functions you are calling are modifying the value of the passed params as well as returning them. Could you post the code of one?
 
Share this answer
 
Comments
ready to learn 30-Jun-11 10:32am    
sorry this is true:
private Bitmap gray(Bitmap bm)
{
st_g.Start();
int cal;
BitmapData bmdata = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
IntPtr scan0 = bmdata.Scan0;
int stride = bmdata.Stride;
unsafe
{
byte* p = (byte*)(void*)scan0;
int offset = stride - (bm.Width * 3);
for (int i = 0; i < bm.Height; i++)
{
for (int j = 0; j < bm.Width; j++)
{
cal =Convert.ToInt32( (p[0] + p[1] + p[2])/3);
p[0] = p[1] = p[2] = (byte)cal;


p += 3;
}
p += offset;
}
}
bm.UnlockBits(bmdata);
st_g.Stop();
return bm;
}
wizardzz 30-Jun-11 10:37am    
Yeah, you are returning the passed parameter after modifying it.
ready to learn 30-Jun-11 10:40am    
can you please change the code so that this problem doesn't take place?I return the image in another one
BobJanova 30-Jun-11 11:01am    
Try using Image.Clone first in each function, e.g.

private Bitmap gray(Bitmap bm)
{
bm = (Bitmap)bm.Clone(); // ADD THIS

st_g.Start();
int cal;
BitmapData bmdata = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
...
}
ready to learn 30-Jun-11 11:08am    
thanks a lot.I think it works

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