Click here to Skip to main content
15,892,809 members

get pixel value by(x,y) simultan with vs2008 c#

bagus bujangga asked:

Open original thread
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 :D
Tags: C#, Image, Image Processing

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900