public static ComplexImage FromBitmap(Bitmap image)
{
// check image format
if (image.PixelFormat != PixelFormat.Format8bppIndexed)
{
throw new UnsupportedImageFormatException("Source image can be graysclae (8bpp indexed) image only.");
}
// lock source bitmap data
BitmapData imageData = image.LockBits(
new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
ComplexImage complexImage;
try
{
complexImage = FromBitmap(imageData);
}
finally
{
// unlock source images
image.UnlockBits(imageData);
}
return complexImage;
}