Click here to Skip to main content
16,020,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a source code for digital image processing.
In my code there is Scanline from top left. I want also Scanline from direction top right, bottom left, bottom right. How can this be done?

private void button4_Click(object sender, EventArgs e)
        {
            // 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;

                for (int y = 0; y < RImage.Height; ++y)
                {                   
                    for (int x = 0; x < RImage.Width; ++x)
                    {
                       
                        //supaya setiap y baru seed juga baru
                        if ((x == 0) || (seedR == 0))
                        {                            
                            //mengambil value seed
                            seedR = p[x];
                            seedG = p[x+1];
                            seedB = p[x+2];
                        }
                        else
                        {
                            if ((seedR - p[x] >= tred) || (p[x] - seedR >= tred))
                            {
                                for (int i = 0; i < 2; ++i)
                                {
                                    p[x] = p[x + 1] = p[x + 2] = 255;
                                    ++x;
                                }
                                                                    
                                seedR = 0;
                                seedG = 0;
                                seedB = 0;
                            }
                        }                        
                        
                        
                        p += 3;
                    }
                    p += nOffset;
                }
            }

            RImage.UnlockBits(bmData);
        }
Posted
Updated 25-Dec-10 22:30pm
v2
Comments
E.F. Nijboer 26-Dec-10 9:23am    
// GDI+ still lies to us - the return format is BGR, NOT RGB.
It does not lie, this becuse your processor is so called "little endian" and because you read it per bytes it looks like BGR but really isn't.

1 solution

You cannot change the "direction" of scan line.

Importantly, you never need to.

You should understand, that all you pointer calculation (I'm referring to your code sample) never change actual bitmap data until you call UnlockBits, and bitmap data goes to screen only when you actually draw your bitmap using your Graphics object.

You certainly have something else in mind, but you need to explain the application of what you want. Nevertheless, whatever it is, scan line will work the same way.
 
Share this answer
 
Comments
Espen Harlinn 28-Feb-11 15:38pm    
Right, my 5
Sergey Alexandrovich Kryukov 1-Mar-11 3:54am    
Accessing bits in the image is somewhat delicate thing.
Thank you, Espen,
--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