Click here to Skip to main content
16,020,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
// GDI+ still lies to us - the return format is BGR, NOT RGB.
            BitmapData bmData = RImage.LockBits(new Rectangle(0, 0, RImage.Width, RImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            int stride = bmData.Stride;
            System.IntPtr Scan0 = bmData.Scan0;

            unsafe
            {
                byte* p = (byte*)(void*)Scan0;

                int nOffset = stride - RImage.Width * 3;

                byte red, green, blue;

                for (int y = 0; y < RImage.Height; ++y)
                {
                    for (int x = 0; x < RImage.Width; ++x)
                    {
                        blue = p[0];
                        green = p[1];
                        red = p[2];

                        p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue);

                        p += 3;
                    }
                    p += nOffset;
                }
            }

            RImage.UnlockBits(bmData);



lines of code in the example above we can see, that we see the pixels one by one from left to right.
or can be explained from x = 0 to x = max.
then down to y

for different issues I want to see and change one by one pixel from the top to the down.
or can be explained from the y = 0 to y = max.
then right onto x

Is this possible?
or perhaps this could
1. from x = max down to x = 0. then y.
2. of y = max down until y = 0. then x.
Posted
Comments
Sergey Alexandrovich Kryukov 27-Dec-10 8:58am    
In "for different issues I want to see and change..." what do you mean by "see"?
The way you do it you always see all changes at once. Do you want to see it in a different way? Then, how?

1 solution

Is looks like you're talking about the order of modification of bit values.

You can do whatever you want. But the order of operation does not matter!
Bitmap data is not really changed until you call UnlockBits; and on-screen image does not change until you call Graphics.DrawImage with updated bitmap.

Please also see my comment to the question.
If you want to see the process of modification in animation or something like that -- this is quite different story.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Dec-10 22:00pm    
Thank you for accepting my answer.
Would you also consider voting?

Good luck and best wishes in New Year!
Espen Harlinn 28-Feb-11 15:14pm    
My 5, is better then none - or so I hope :)
Sergey Alexandrovich Kryukov 1-Mar-11 3:38am    
Much better, thank you.
Sure, if OP get final answer which help to get back to work, the OP's interest is already lost...
--SA

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