BitmapExtensionsInvert Method
Inverts the colors of the specified
bitmap.
See the
online help for a couple of examples with images.
Namespace: KGySoft.DrawingAssembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 10.0.0-rc.1
public static void Invert(
this Bitmap bitmap,
IDitherer? ditherer = null
)
<ExtensionAttribute>
Public Shared Sub Invert (
bitmap As Bitmap,
Optional ditherer As IDitherer = Nothing
)
public:
[ExtensionAttribute]
static void Invert(
Bitmap^ bitmap,
IDitherer^ ditherer = nullptr
)
[<ExtensionAttribute>]
static member Invert :
bitmap : Bitmap *
?ditherer : IDitherer
(* Defaults:
let _ditherer = defaultArg ditherer null
*)
-> unit
- bitmap Bitmap
- The Bitmap to be inverted.
- ditherer IDitherer (Optional)
- An optional IDitherer instance to dither the result of the transformation if the inverse of the bitmap
has no exact representation with its PixelFormat. This parameter is optional.
Default value: .
In Visual Basic and C#, you can call this method as an instance method on any object of type
Bitmap. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
using Bitmap bmp = Icons.Shield.ExtractBitmap(new Size(256, 256));
bmp.SaveAsPng(@"c:\temp\before.png");
bmp.Invert();
bmp.SaveAsPng(@"c:\temp\after.png");
The example above produces the following results:
| before.png |  |
| after.png |  |
This method uses the color space that naturally matches the pixel format of the
bitmap. In
Example 1 the
original bitmap had a 32 BPP pixel format, so the sRGB color space was used. To specify a color space explicitly, you can obtain an
IReadWriteBitmapData instance
and use the
BitmapDataExtensions.Invert method instead:
using Bitmap bmp = Icons.Shield.ExtractBitmap(new Size(256, 256));
bmp.SaveAsPng(@"c:\temp\before.png");
using (IReadWriteBitmapData bitmapData = bmp.GetReadWriteBitmapData(WorkingColorSpace.Linear))
bitmapData.Invert();
bmp.SaveAsPng(@"c:\temp\after.png");
The example above produces the following results:
| before.png |  |
| after.png |  |