Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a bitmap in which i am taking only 9 pixels.

each pixel will have rgb value...i have created an array of 3 * 3 size.

each pixel rgb value is taken separately and loaded in a list box.

after all iterations the no of values in list box will be 27...

till here it is fine.

when i run the application ,,,the listbox gets loaded with all 27 values..but after some 10 to 15 secons...i c the count is increasing again to to 54...sometimes 81...and so on...why is this happening

i have taken the bmp in a picture box..in the form...the code is written in picturebox_paint event...is this a mistake...

first when R is calculated for fist pixel it will go to a function called add...from picturebox1_paint event..where the listbox will get added with R value..and then goes to loop again...similarily for G and B values.

here is the brief code:

pictureBox1_Paint event
{
for (i = 0; i < 3; i++)
{

for (j = 0; j < 3; j++)
{
Color pixelColor = bm.GetPixel(i, j);
b = pixelColor.R;
ADDINARRAY(b);

c = pixelColor.G;
ADDINARRAY(c);
d = pixelColor.B;
ADDINARRAY(d);






}
}
}


// this is the code for items to get loaded in listbox
void ADDINARRAY(int value)
{

listBox1.Items.Add(value);
}
Posted
Updated 22-Feb-13 23:49pm
v3
Comments
Richard MacCutchan 23-Feb-13 5:43am    
I can only assume that you are calling the ListBox update method from somewhere that is getting repeated. Thus you are adding the same number of values multiple times. Edit your question and show some of your code so we can try to help you.

1 solution

"the code is written in picturebox_paint event"
Yes.

The Paint event is called every time the PictureBox needs to be updated by the system. It is doing exactly what it should.

Either move the code to a much more appropriate event, or Clear the Listbox content before you fill it with new data.
Personally, I'd do both!
 
Share this answer
 
Comments
luckycode 23-Feb-13 5:59am    
thank you...problem solved...
OriginalGriff 23-Feb-13 6:08am    
You're welcome!

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