ImageExtensionsToIcon(Image, Color) Method

Creates an Icon from an Image.

Definition

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

Parameters

image  Image
The image to be converted to an icon.
transparentColor  Color  (Optional)
A color that represents transparent color for the icon to be created. Ignored if the image is large and will be PNG compressed. This parameter is optional.
Default value: Empty, which keeps only already transparent pixels.

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 create 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.

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

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

See Also