public static Bitmap ToBitmap( float[,] texture )
{
// get texture dimension
int width = texture.GetLength( 1 );
int height = texture.GetLength( 0 );
// create new grawscale image
Bitmap dstImage = AForge.Imaging.Image.CreateGrayscaleImage( width, height );
// lock destination bitmap data
BitmapData dstData = dstImage.LockBits(
new Rectangle( 0, 0, width, height ),
ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed );
// do the job
unsafe
{
byte* dst = (byte*) dstData.Scan0.ToPointer( );
int offset = dstData.Stride - width;
// for each line
for ( int y = 0; y < height; y++ )
{
// for each pixel
for ( int x = 0; x < width; x++, dst++ )
{
*dst = (byte) ( texture[y, x] * 255.0f );
}
dst += offset;
}
}
// unlock destination images
dstImage.UnlockBits( dstData );
return dstImage;
}