public void DisplayImage16(string fileName) { try { BinaryReader br = new BinaryReader(File.Open(fileName, FileMode.Open)); ushort pixShort; int i; long iTotalSize = br.BaseStream.Length; int iNumberOfPixels = (int)(iTotalSize / 2); // Get the dimensions of the image from the user ID = new ImageDimentions(iNumberOfPixels); if (ID.ShowDialog() == true) { width = Convert.ToInt32(ID.tbWidth.Text); height = Convert.ToInt32(ID.tbHeight.Text); canvas.Width = width; canvas.Height = height; img.Width = width; img.Height = height; pix16 = new ushort[iNumberOfPixels]; for (i = 0; i < iNumberOfPixels; ++i) { pixShort = (ushort)(br.ReadUInt16()); pix16[i] = pixShort ; } br.Close(); int bitsPerPixel = 16; stride = (width * bitsPerPixel + 7) / 8; // Single step creation of the image bmps = BitmapSource.Create(width, height, 96, 96, PixelFormats.Gray16, null, pix16, stride); img.Source = bmps; btnSavejpg.IsEnabled = true; btnSavePng.IsEnabled = true; } else { br.Close(); } } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)