internal async void LoadImage(string text, bool IsBase64 = false) { if (IsBase64) { using (MemoryStream imageStream = new MemoryStream()) { imageStream.Position = 0; var base64 = Regex.Replace(text, @"data:image/.*?;base64,", "", RegexOptions.IgnoreCase); byte[] arr = Convert.FromBase64String(base64); await imageStream.WriteAsync(arr, 0, arr.Length); await imageStream.FlushAsync(); imageStream.Seek(0, SeekOrigin.Begin); var result = new BitmapImage(); result.BeginInit(); result.StreamSource = imageStream; result.CacheOption = BitmapCacheOption.OnLoad; result.EndInit(); LoadImage(result); } } else { p2m.FileName = System.IO.Path.GetFileNameWithoutExtension(text); bitmap = PixelMidi.LoadBitmap(text); image.Source = PixelMidi.BitmapToImageSource(PixelMidi.GrayScale(bitmap)); //p2m.GetPixelMidi(bitmap, !MultiTrack.IsChecked.Value); } }
internal void LoadImage(BitmapSource source) { if (source is BitmapSource) { bitmap = PixelMidi.ImageSourceToBitmap(source as BitmapSource); image.Source = PixelMidi.BitmapToImageSource(PixelMidi.GrayScale(bitmap)); } }
private void InvertImage_Click(object sender, RoutedEventArgs e) { p2m.InvertSource = InvertImage.IsChecked.Value; if (p2m.InvertSource) { image.Source = PixelMidi.BitmapToImageSource(PixelMidi.Invert(bitmap)); } else { image.Source = PixelMidi.BitmapToImageSource(bitmap); } //p2m.GetPixelMidi(bitmap); }
internal void LoadImage(Stream stream, bool IsDib = true) { try { if (stream is Stream) { if (IsDib) { bitmap = BitmapFromDib(stream); } else { bitmap = new System.Drawing.Bitmap(stream); } image.Source = PixelMidi.BitmapToImageSource(PixelMidi.GrayScale(bitmap)); } } catch (Exception) { } }
internal void LoadImage(Uri url) { try { if (url is Uri) { BitmapImage img = new BitmapImage(); img.BeginInit(); img.UriSource = url; img.CacheOption = BitmapCacheOption.OnLoad; img.EndInit(); if (img is BitmapSource) { bitmap = PixelMidi.ImageSourceToBitmap(img as BitmapSource); image.Source = PixelMidi.BitmapToImageSource(PixelMidi.GrayScale(bitmap)); } } } catch (Exception) { } }