AForge.Imaging.Image.Clone C# (CSharp) Метод

Clone() публичный статический Метод

Clone image.
public static Clone ( BitmapData sourceData ) : Bitmap
sourceData System.Drawing.Imaging.BitmapData Source image data.
Результат System.Drawing.Bitmap
        public static Bitmap Clone( BitmapData sourceData )
        {
            // get source image size
            int width = sourceData.Width;
            int height = sourceData.Height;

            // create new image
            Bitmap destination = new Bitmap( width, height, sourceData.PixelFormat );

            // lock destination bitmap data
            BitmapData destinationData = destination.LockBits(
                new Rectangle( 0, 0, width, height ),
                ImageLockMode.ReadWrite, destination.PixelFormat );

            AForge.SystemTools.CopyUnmanagedMemory( destinationData.Scan0, sourceData.Scan0, height * sourceData.Stride );

            // unlock destination image
            destination.UnlockBits( destinationData );

            return destination;
        }

Same methods

Image::Clone ( Bitmap source ) : Bitmap
Image::Clone ( Bitmap source, PixelFormat format ) : Bitmap

Usage Example

 public static Bitmap OpenImage(this TextStructure filePath)
 {
     try
     {
         using (var bitmap = new Bitmap(filePath.Value))
         {
             return(Image.Clone(bitmap, PixelFormat.Format24bppRgb));
         }
     }
     catch (Exception ex)
     {
         throw new Exception($"Could not open the image file '{filePath.Value}'. Message: {ex.Message}", ex);
     }
 }
All Usage Examples Of AForge.Imaging.Image::Clone