BitmapDataExtensionsMakeTransparent(IReadWriteBitmapData, Color32) Method
If possible, makes the background of this
bitmapData transparent, using
transparentColor as the background color.
If the
bitmapData does not support transparency, then the pixels that have the same color as
transparentColor will be set
to the
BackColor of
bitmapData.
Namespace: KGySoft.Drawing.ImagingAssembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.0.0-preview.1
public static void MakeTransparent(
this IReadWriteBitmapData bitmapData,
Color32 transparentColor
)
<ExtensionAttribute>
Public Shared Sub MakeTransparent (
bitmapData As IReadWriteBitmapData,
transparentColor As Color32
)
public:
[ExtensionAttribute]
static void MakeTransparent(
IReadWriteBitmapData^ bitmapData,
Color32 transparentColor
)
[<ExtensionAttribute>]
static member MakeTransparent :
bitmapData : IReadWriteBitmapData *
transparentColor : Color32 -> unit
- bitmapData IReadWriteBitmapData
- The IReadWriteBitmapData to make transparent.
- transparentColor Color32
- Specifies the color to make transparent.
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).
This method adjusts the degree of parallelization automatically, blocks the caller, and does not support cancellation or reporting progress. Use the
BeginMakeTransparent(IReadWriteBitmapData, Color32, AsyncConfig)
or
MakeTransparentAsync(IReadWriteBitmapData, Color32, TaskConfig) (in .NET Framework 4.0 and above) methods for asynchronous call and to adjust parallelization, set up cancellation and for reporting progress.
This method calls the ReplaceColor method internally.
Unlike the Bitmap.MakeTransparent(Color) method,
this one preserves the original PixelFormat. If bitmapData does not support transparency and cannot set Palette either,
then every occurrence of the transparentColor will be changed to the BackColor of bitmapData.
To make such bitmaps transparent use the ToTransparent method instead,
which returns a new instance with Format32bppArgb PixelFormat.
To auto-detect the background color to be made transparent use the MakeTransparent(IReadWriteBitmapData) overload instead.
Please note that unlike the
MakeOpaque method, this one changes exactly one color shade without any tolerance.
For any customization use the
TransformColors method instead.