Bild invertieren

C4Dlooser

Erfahrenes Mitglied
Hey
Ich würde gern bei einem Button Klick ein bild invertieren.
wenn jemand von euch da bescheid weis wäre das sehr interessant aber schreibt bitte keine Riesen Codes hier rein (So wichtig ist es auch nicht)

Gruß C4Dlooser
 
Hi.

C#:
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]);
                ++p;
            }
            p += nOffset;
        }
    }

    b.UnlockBits(bmData);

    return true;
}
Quelle: Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters

lg,..
 
Zurück