New to Telerik UI for WinFormsStart a free 30-day trial

Provides utility methods for image manipulation, processing, and conversion operations.

Definition

Namespace:Telerik.WinControls

Assembly:Telerik.WinControls.dll

Syntax:

C#
public static class ImageHelper

Inheritance: objectImageHelper

Methods

Applies a uniform alpha (transparency) value to all pixels in the specified bitmap.

C#
public static void ApplyAlpha(Bitmap bitmap, float fAlpha)
Parameters:bitmapBitmap

The bitmap to modify. Must be in 32bpp ARGB format.

fAlphafloat

The alpha value to apply, ranging from 0.0 (fully transparent) to 1.0 (fully opaque).

Remarks:

Directly modifies the alpha channel of each pixel using unsafe code for optimal performance. The bitmap must be in 32bpp ARGB format. Commonly used for fade effects and transparency adjustments.

Applies a brush-based alpha mask to a bitmap, modifying the transparency of pixels based on the brush pattern.

C#
public static void ApplyMask(Bitmap bitmap, Brush brush)
Parameters:bitmapBitmap

The bitmap to apply the mask to.

brushBrush

The brush defining the alpha mask pattern. The brush's color values determine the transparency.

Remarks:

This method creates a temporary bitmap filled with the specified brush pattern, then uses the red channel values from this pattern as alpha values for the original bitmap. This allows for complex transparency effects based on gradients, patterns, or solid colors.

The masking process:

  1. Creates a temporary bitmap the same size as the original
  2. Fills the temporary bitmap with the brush pattern
  3. Uses the red channel values as alpha channel values for each corresponding pixel

This is useful for creating fade effects, vignettes, and complex transparency patterns.

C#
public static bool AreColorsSame(Color color1, Color color2)
Parameters:color1Colorcolor2ColorReturns:

bool

C#
public static Bitmap BitmapInvertColors(Bitmap original)
Parameters:originalBitmapReturns:

Bitmap

C#
public static Image ChangeImagePixels(Image image, Color color)
Parameters:imageImagecolorColorReturns:

Image

Converts the image to Device Independent Bitmap format of type BITFIELDS. This is (wrongly) accepted by many applications as containing transparency

C#
public static byte[] ConvertToDib(Image image)
Parameters:imageImage

Image to convert to DIB

Returns:

byte[]

The image converted to DIB, in bytes.

Copies given image to the clipboard. Different applications understand different image formats, so this method applies the three most common image formats to the data object - Bitmap, PNG and DIB.

C#
public static void CopyImageToClipboard(Image image)
Parameters:imageImage

The image to copy.

Crops a rectangular region from a bitmap and returns it as a new bitmap with high-quality rendering.

C#
public static Bitmap Crop(Bitmap image, Rectangle cropRectangle)
Parameters:imageBitmap

The source bitmap to crop from.

cropRectangleRectangle

The rectangular region to extract from the source image, in pixel coordinates.

Returns:

Bitmap

A new Bitmap containing the cropped region, with dimensions matching the crop rectangle.

Remarks:

This method creates a new bitmap with the exact dimensions of the crop rectangle and draws the specified region from the source image using high-quality rendering settings:

  • Anti-aliased smoothing for clean edges
  • High-quality bicubic interpolation for smooth scaling
  • High-quality pixel offset mode for precise positioning

The crop rectangle coordinates are relative to the source image. If the rectangle extends beyond the source image boundaries, the out-of-bounds areas will be filled with transparent pixels.

The caller is responsible for disposing of the returned bitmap when no longer needed.

C#
public static GraphicsPath GetBitmapRegionPath(Bitmap bmp, Color transparent)
Parameters:bmpBitmaptransparentColorReturns:

GraphicsPath

C#
public static byte[] GetBytesFromImage(Image image)
Parameters:imageImageReturns:

byte[]

Gets image from the clipboard and preserves pixel transparency. If there is no image data in the clipboard, returns null.

C#
public static Image GetClipboardImage()
Returns:

Image

The image from clipboard.

Retrieves an image from the given clipboard data object, in the order PNG, DIB, Bitmap, Image object.

C#
public static Bitmap GetClipboardImage(DataObject clipboardData)
Parameters:clipboardDataDataObject

The clipboard data.

Returns:

Bitmap

The extracted image, or null if no supported image type was found.

Gets the raw bytes from an image.

C#
public static byte[] GetImageData(Bitmap sourceImage, out int stride)
Parameters:sourceImageBitmap

The image to get the bytes from.

strideint

Stride of the retrieved image data.

Returns:

byte[]

The raw bytes of the image

C#
public static Image GetImageFromBytes(byte[] bytes)
Parameters:bytesbyte[]Returns:

Image

C#
public static Color HslToRgb(double h, double s, double l, double a)
Parameters:hdoublesdoubleldoubleadoubleReturns:

Color

C#
public static bool IsDarkColor(Color color)
Parameters:colorColorReturns:

bool

C#
public static bool PointInRegion(Region region, Point client)
Parameters:regionRegionclientPointReturns:

bool

C#
public static Region RegionFromBitmap(Bitmap bmp, Color transparent)
Parameters:bmpBitmaptransparentColorReturns:

Region