try { BinaryReader br = new BinaryReader(image); byte pixByte; int i; int iTotalSize = (int)br.BaseStream.Length; // Get the dimensions of the image from the user ID = new ImageDimensions(iTotalSize); 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; pix08 = new byte[iTotalSize]; for (i = 0; i < iTotalSize; ++i) { pixByte = (byte)(br.ReadByte()); pix08[i] = pixByte; } br.Close(); int bitsPerPixel = 8; stride = (width * bitsPerPixel + 7) / 8; // Single step creation of the image bmps = BitmapSource.Create(width, height, 96, 96, PixelFormats.Gray8, null, pix08, stride); img.Source = bmps; } else { br.Close(); } } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); }
var base64 = Convert.ToBase64String(image); var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)