ImageExtensionsToIcon(Image, Color) Method

Creates an Icon from an Image.

Definition

Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 10.1.0
C#
public static Icon ToIcon(
	this Image image,
	Color transparentColor
)

Parameters

image  Image
The image to be converted to an icon.
transparentColor  Color
A color that represents transparent color for the icon to be created. Ignored if the image is large and will be PNG compressed.

Return Value

Icon
An Icon instance created from the image that has the same size as the specified image.

Usage Note

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

The result icon will have the same size as the specified image. To force creating a squared icon, use the ToIcon(Image, Int32, Boolean) overload instead.

If the raw format of image is an icon that contains multiple images, then the result will also contain multiple resolutions.

To disable PNG compression also for large images regardless of the current operating system use the Combine(Bitmap, Color, Boolean) method instead.

This overload attempts to preserve the actual pixel format of the specified image, and just applies a transparency mask for the specified color. To allow reducing the color depth losslessly, use the ToIcon(Image) overload instead.

If transparentColor is an opaque color and image already has transparent pixels, then both the originally transparent pixels, and the ones that equal to transparentColor will be transparent in the result.

The result Icon is compatible with Windows XP if the method is executed in a Windows XP environment.

See Also