public static Clone ( |
||
sourceData | Source image data. | |
return |
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;
}
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); } }