Image in unmanaged memory.

Namespace:  AForge.Imaging
Assembly:  AForge.Imaging (in AForge.Imaging.dll) Version: (


public class UnmanagedImage : IDisposable


The class represents wrapper of an image in unmanaged memory. Using this class it is possible as to allocate new image in unmanaged memory, as to just wrap provided pointer to unmanaged memory, where an image is stored.

Usage of unmanaged images is mostly beneficial when it is required to apply multiple image processing routines to a single image. In such scenario usage of .NET managed images usually leads to worse performance, because each routine needs to lock managed image before image processing is done and then unlock it after image processing is done. Without these lock/unlock there is no way to get direct access to managed image's data, which means there is no way to do fast image processing. So, usage of managed images lead to overhead, which is caused by locks/unlock. Unmanaged images are represented internally using unmanaged memory buffer. This means that it is not required to do any locks/unlocks in order to get access to image data (no overhead).

Sample usage:

// sample 1 - wrapping .NET image into unmanaged without
// making extra copy of image in memory
BitmapData imageData = image.LockBits(
    new Rectangle( 0, 0, image.Width, image.Height ),
    ImageLockMode.ReadWrite, image.PixelFormat );
    UnmanagedImage unmanagedImage = new UnmanagedImage( imageData ) );
    // apply several routines to the unmanaged image
    image.UnlockBits( imageData );
// sample 2 - converting .NET image into unmanaged
UnmanagedImage unmanagedImage = UnmanagedImage.FromManagedImage( image );
// apply several routines to the unmanaged image
// conver to managed image if it is required to display it at some point of time
Bitmap managedImage = unmanagedImage.ToManagedImage( );

Inheritance Hierarchy


See Also