AForge.Imaging.UnmanagedImage.Copy C# (CSharp) Method

Copy() public method

Copy unmanaged image.

The method copies current unmanaged image to the specified image. Size and pixel format of the destination image must be exactly the same.

Destination image has different size or pixel format.
public Copy ( UnmanagedImage destImage ) : void
destImage UnmanagedImage Destination image to copy this image to.
return void
        public void Copy( UnmanagedImage destImage )
        {
            if (
                ( width != destImage.width ) || ( height != destImage.height ) ||
                ( pixelFormat != destImage.pixelFormat ) )
            {
                throw new InvalidImagePropertiesException( "Destination image has different size or pixel format." );
            }

            if ( stride == destImage.stride )
            {
                // copy entire image
                AForge.SystemTools.CopyUnmanagedMemory( destImage.imageData, imageData, stride * height );
            }
            else
            {
                unsafe
                {
                    int dstStride = destImage.stride;
                    int copyLength = ( stride < dstStride ) ? stride : dstStride;

                    byte* src = (byte*) imageData.ToPointer( );
                    byte* dst = (byte*) destImage.imageData.ToPointer( );

                    // copy line by line
                    for ( int i = 0; i < height; i++ )
                    {
                        AForge.SystemTools.CopyUnmanagedMemory( dst, src, copyLength );

                        dst += dstStride;
                        src += stride;
                    }
                }
            }
        }

Usage Example

Beispiel #1
0
 public static void ConvertToGrayscale(UnmanagedImage source, UnmanagedImage destination)
 {
     if (source.PixelFormat != PixelFormat.Format8bppIndexed)
     {
         Grayscale.CommonAlgorithms.BT709.Apply(source, destination);
     }
     else
     {
         source.Copy(destination);
     }
 }
All Usage Examples Of AForge.Imaging.UnmanagedImage::Copy