示例#1
0
        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);
            }
        }
示例#2
0
 internal void LoadImage(BitmapSource source)
 {
     if (source is BitmapSource)
     {
         bitmap       = PixelMidi.ImageSourceToBitmap(source as BitmapSource);
         image.Source = PixelMidi.BitmapToImageSource(PixelMidi.GrayScale(bitmap));
     }
 }
示例#3
0
 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) { }
 }
示例#4
0
        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) { }
        }