BitmapDataExtensionsMakeTransparent(IReadWriteBitmapData) Method

If possible, makes the background of this bitmapData transparent, taking the bottom-left pixel as the background color. If the bitmapData does not support transparency, then the pixels that have the same color as the bottom-left pixel will be set to the BackColor of bitmapData.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.0-rc.1
C#
public static void MakeTransparent(
	this IReadWriteBitmapData bitmapData
)

Parameters

bitmapData  IReadWriteBitmapData
The IReadWriteBitmapData to make transparent.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IReadWriteBitmapData. 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).

Remarks

  Note

This method adjusts the degree of parallelization automatically, blocks the caller, and does not support cancellation or reporting progress. You can use the MakeTransparent(IReadWriteBitmapData, ParallelConfig) overload to configure these, while still executing the method synchronously. Alternatively, use the BeginMakeTransparent(IReadWriteBitmapData, AsyncConfig) or MakeTransparentAsync(IReadWriteBitmapData, TaskConfig) (in .NET Framework 4.0 and above) methods for asynchronous call and to adjust parallelization, set up cancellation and for reporting progress.

Similarly to the Bitmap.MakeTransparent method, this one uses the bottom-left pixel to determine the background color, which must be completely opaque; otherwise, bitmapData will not be changed.

Unlike the Bitmap.MakeTransparent method, this one preserves the original PixelFormat. If bitmapData does not support transparency and cannot set Palette either, then every occurrence of the color of the bottom-left pixel will be changed to the BackColor of bitmapData. To make such bitmaps transparent use the ToTransparent method instead, which returns a new instance that has a PixelFormat with alpha support.

To force replacing even non-completely opaque pixels use the MakeTransparent(IReadWriteBitmapData, Color32) overload instead.

  Note

Please note that unlike the MakeOpaque method, this one changes exactly one color shade without any tolerance. For customizations use the TransformColors overloads instead.

See Also