Beispiel #1
0
        /// <summary>
        /// Convert a UInt16IntensityImage to a Bitmap image.
        /// </summary>
        /// <param name="image">Image to convert.</param>
        /// <returns>Bitmap image.</returns>
        public static Bitmap ToBitmap(this UInt16IntensityImage image, UInt16 scalingMaxValue, UInt16 Zmap_Offset)
        {
            Bitmap bitmap        = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            int    bytesPerPixel = Bitmap.GetPixelFormatSize(bitmap.PixelFormat) / 8;

            byte[] imageData = new byte[bytesPerPixel * image.Width * image.Height];

            for (int y = 0; y < image.Height; y++)
            {
                int stereoOffset = y * image.Width;
                int imageOffset  = y * image.Width * 3;
                for (int x = 0; x < image.Width; x++)
                {
                    // Scale from 16-bit to 8-bit
                    byte pixelValue = (byte)(((image.Data[stereoOffset + x] + Zmap_Offset) / (double)scalingMaxValue) * byte.MaxValue);

                    // TODO: Scale to 8-bit instead of wrap
                    imageData[imageOffset + (x * bytesPerPixel)]     = pixelValue;
                    imageData[imageOffset + (x * bytesPerPixel) + 1] = pixelValue;
                    imageData[imageOffset + (x * bytesPerPixel) + 2] = pixelValue;
                }
            }

            // Copy pixels into bitmap image
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);

            Marshal.Copy(imageData, 0, bitmapData.Scan0, imageData.Length);
            bitmap.UnlockBits(bitmapData);

            return(bitmap);
        }
Beispiel #2
0
 /// <summary>
 /// Convert a UInt16IntensityImage to a Bitmap image.
 /// </summary>
 /// <param name="image">Image to convert.</param>
 /// <returns>Bitmap image.</returns>
 public static Bitmap ToBitmap(this UInt16IntensityImage image)
 {
     return(image.ToBitmap(UInt16.MaxValue, UInt16.MaxValue));
 }