Click or drag to resize
Accord.NET (logo)

UnmanagedImage Class

Image in unmanaged memory.
Inheritance Hierarchy
SystemObject
  Accord.ImagingUnmanagedImage

Namespace:  Accord.Imaging
Assembly:  Accord.Imaging (in Accord.Imaging.dll) Version: 3.8.0
Syntax
public class UnmanagedImage : IDisposable
Request Example View Source

The UnmanagedImage type exposes the following members.

Constructors
  NameDescription
Public methodUnmanagedImage(BitmapData)
Initializes a new instance of the UnmanagedImage class.
Public methodUnmanagedImage(IntPtr, Int32, Int32, Int32, PixelFormat)
Initializes a new instance of the UnmanagedImage class.
Top
Properties
  NameDescription
Public propertyBytes
Gets the image size, in bytes.
Public propertyHeight
Image height in pixels.
Public propertyImageData
Pointer to image data in unmanaged memory.
Public propertyOffset
Gets the number of extra bytes after the image width is over. This can be computed as Stride - Width * PixelSize.
Public propertyPixelFormat
Image pixel format.
Public propertyPixelSize
Gets the size of the pixels in this image, in bytes. For example, a 8-bpp grayscale image would have pixel size 1.
Public propertySize
Gets the image size, in pixels.
Public propertyStride
Image stride (line size in bytes).
Public propertyWidth
Image width in pixels.
Top
Methods
  NameDescription
Public methodClone
Clone the unmanaged images.
Public methodCollect16bppPixelValues
Collect pixel values from the specified list of coordinates.
Public methodCollect8bppPixelValues
Collect pixel values from the specified list of coordinates.
Public methodCollectActivePixels
Collect coordinates of none black pixels in the image.
Public methodCollectActivePixels(Rectangle)
Collect coordinates of none black pixels within specified rectangle of the image.
Public methodCopy
Copy unmanaged image.
Public methodStatic memberCreate(Int32, Int32, PixelFormat)
Allocate new image in unmanaged memory.
Public methodStatic memberCreate(Int32, Int32, Int32, PixelFormat)
Allocate new image in unmanaged memory.
Public methodDispose
Dispose the object.
Protected methodDispose(Boolean)
Dispose the object.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Destroys the instance of the UnmanagedImage class.
(Overrides ObjectFinalize.)
Public methodStatic memberFromByteArray
Create unmanaged image from the specified byte array.
Public methodStatic memberFromManagedImage(Bitmap)
Create unmanaged image from the specified managed image.
Public methodStatic memberFromManagedImage(BitmapData)
Create unmanaged image from the specified managed image.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetPixel(IntPoint)
Get color of the pixel with the specified coordinates.
Public methodGetPixel(Int32, Int32)
Get color of the pixel with the specified coordinates.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodSetPixel(IntPoint, Color)
Set pixel with the specified coordinates to the specified color.
Public methodSetPixel(Int32, Int32, Byte)
Set pixel with the specified coordinates to the specified value.
Public methodSetPixel(Int32, Int32, Color)
Set pixel with the specified coordinates to the specified color.
Public methodSetPixels
Set pixels with the specified coordinates to the specified color.
Public methodToByteArray
Converts the image into a sequence of bytes.
Public methodToManagedImage
Create managed image from the unmanaged.
Public methodToManagedImage(Boolean)
Create managed image from the unmanaged.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodGetPixelFormatSize
Gets the color depth used in an image, in number of bits per pixel.
(Defined by Image.)
Public Extension MethodGetPixelFormatSizeInBytes
Gets the color depth used in an image, in number of bytes per pixel.
(Defined by Image.)
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodMaxOverloaded.
Computes the maximum pixel value in the given image.
(Defined by Tools.)
Public Extension MethodMax(Rectangle)Overloaded.
Computes the maximum pixel value in the given image.
(Defined by Tools.)
Public Extension MethodMax(Int32)Overloaded.
Computes the maximum pixel value in the given image.
(Defined by Tools.)
Public Extension MethodMeanOverloaded.
Computes the arithmetic mean of the pixels in a given image.
(Defined by Tools.)
Public Extension MethodMean(Rectangle)Overloaded.
Computes the arithmetic mean of the pixels in a given image.
(Defined by Tools.)
Public Extension MethodMinOverloaded.
Computes the minimum pixel value in the given image.
(Defined by Tools.)
Public Extension MethodMin(Int32)Overloaded.
Computes the maximum pixel value in the given image.
(Defined by Tools.)
Public Extension MethodMin(Rectangle)Overloaded.
Computes the minimum pixel value in the given image.
(Defined by Tools.)
Public Extension MethodStandardDeviation(Double)Overloaded.
Computes the standard deviation of image pixels.
(Defined by Tools.)
Public Extension MethodStandardDeviation(Rectangle, Double)Overloaded.
Computes the standard deviation of image pixels.
(Defined by Tools.)
Public Extension MethodSumOverloaded.
Computes the sum of the pixels in a given image.
(Defined by Tools.)
Public Extension MethodSum(Rectangle)Overloaded.
Computes the sum of the pixels in a given image.
(Defined by Tools.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

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 );

try
{
    UnmanagedImage unmanagedImage = new UnmanagedImage( imageData ) );
    // apply several routines to the unmanaged image
}
finally
{
    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( );
See Also