Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello, I found this code in Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^]
 
I found I can't understand code, here this code:
 
public static bool Invert(Bitmap b)
{
    // GDI+ still lies to us - the return format is BGR, NOT RGB. 

    BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), 
    ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); 
    int stride = bmData.Stride; 
    System.IntPtr Scan0 = bmData.Scan0; 
    unsafe 
    { 
        byte * p = (byte *)(void *)Scan0;
        int nOffset = stride - b.Width*3; 
        int nWidth = b.Width * 3;
        for(int y=0;y < b.Height;++y)
        {
            for(int x=0; x < nWidth; ++x )
            {                                       
                p[0] = (byte)(255-p[0]);    // Here I want to get by pixel(x,y)
                ++p;                        // position simultaneously for exp:
                                            // result= 
                                            // pixel(0,0)+pixel(1,0)+pixel(2,0)
                                            // +pixel(0,1)+pixel(1,1)+ pixel(2,1)
                                            // +pixel(0,2)+pixel(1,2)+ pixel(2,2)
                                            // result=result/9;
                                            
 
            }           
            p += nOffset;                   //for what this function "p+=nOffset"?
        }                                   //I try to disable it and still work
    }
    b.UnlockBits(bmData);
    return true;
}
 
Here I want to get by pixel(x,y) position simultaneously for exp:
result= pixel(0,0)+pixel(1,0)+pixel(2,0)+pixel(0,1)+pixel(1,1)+ pixel(2,1)+pixel(0,2)+pixel(1,2)+ pixel(2,2)result=result/9;
How to do it?
 
and than I don't understand with "p += nOffset;", I try disable it and still running. please explain to me?
 
thanks Big Grin | :-D
Posted 30-Jun-11 18:20pm
Edited 30-Jun-11 22:44pm
v3
Comments
SAKryukov at 1-Jul-11 0:36am
   
This is not a question. You don't explain what exactly is your problem. Look MSDN help pages on each method or type used here, that's it.
--SA
walterhevedeich at 1-Jul-11 1:02am
   
You might also want to post your question on the article. The author knows better about the code than anyone else.
bagus bujangga at 1-Jul-11 4:42am
   
this is my question, I am write in code above.
here I copy this question,
Here I want to get by pixel(x,y) position simultaneously with other pixel value for exp:
(x,y) is position of the pixel.
 
result= pixel(0,0)+pixel(1,0)+pixel(2,0)+pixel(0,1)+pixel(1,1)+
pixel(2,1)+pixel(0,2)+pixel(1,2)+ pixel(2,2)
result=result/9;
 
How to do it?
 
and I don't understand with "p += nOffset;", I try disable it and still running. can you explain to me?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Don't post this under Questions & Answers - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
 
Mind you, I don't think you will get much help with a generic "explain this to me" - you might be better off runnin gthis through teh debugger and watching what happens - it is pretty obvious, after all.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 495
1 OriginalGriff 339
2 ChintanShukla 305
3 Richard Deeming 260
4 RyanDev 230
0 Sergey Alexandrovich Kryukov 8,858
1 OriginalGriff 7,451
2 CPallini 2,603
3 Richard MacCutchan 2,095
4 Abhinav S 1,893


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 1 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100