IconExtensionsExtractNearestBitmap Method

Extracts the nearest image of specified size and pixel format from an Icon instance.


Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 8.1.0
public static Bitmap ExtractNearestBitmap(
	this Icon icon,
	Size size,
	PixelFormat pixelFormat,
	bool keepOriginalFormat = false


icon  Icon
The icon that may contain multiple images.
size  Size
The required icon size to retrieve.
pixelFormat  PixelFormat
The required pixel format to retrieve
keepOriginalFormat  Boolean  (Optional)
If , keeps the original image format stored in the icon. Possible transparent pixels of non-32 bpp ARGB formats may be black. If , always returns 32 bpp images with transparency. This parameter is optional.
Default value: .

Return Value

An Bitmap instance, which was extracted from the icon. If no icon was found with the specified size and format the nearest image (pixelFormat matches first, then size) is returned.

Usage Note

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


On some platforms it may happen that a smaller result is returned than requested if the requested size and format is not supported.

See Also