void CheckTweetData(string text, List <BitmapImage> images) { bool ready = true; foreach (var img in images) { if (img.IsDownloading) { ready = false; break; } } if (ready) { Func <ImageSource, Image> makeImg = source => { var el = new System.Windows.Controls.Image() { Source = source, SnapsToDevicePixels = true, UseLayoutRounding = true, MinWidth = m_messageQueue.Device.Width, MinHeight = m_messageQueue.Device.Height, Width = source.Width * ((BitmapSource)source).DpiX / 96, Stretch = Stretch.UniformToFill, }; RenderOptions.SetBitmapScalingMode(source, BitmapScalingMode.NearestNeighbor); el.Measure(new Size(m_messageQueue.Device.Width, m_messageQueue.Device.Height)); el.Arrange(new Rect(0, 0, m_messageQueue.Device.Width, m_messageQueue.Device.Height)); return(el); }; if (images.Count > 0) { m_messageQueue.Enqueue(new LedBadgeLib.MessageQueueItem(new LedBadgeLib.WpfVisual(m_messageQueue.Device, makeImg(images[0]), dither: Dither))); } m_messageQueue.Enqueue(LedBadgeLib.WPF.MakeQueuedItem(m_messageQueue.Device, LedBadgeLib.WPF.MakeSingleLineItem(m_messageQueue.Device, text))); for (int i = 1; i < images.Count; ++i) { m_messageQueue.Enqueue(new LedBadgeLib.MessageQueueItem(new LedBadgeLib.WpfVisual(m_messageQueue.Device, makeImg(images[i]), dither: Dither))); } } else { Dispatcher.InvokeAsync(() => CheckTweetData(text, images), DispatcherPriority.Background); } }
void CheckImage(BitmapImage img) { if (img.IsDownloading) { Dispatcher.InvokeAsync(() => CheckImage(img), DispatcherPriority.Background); } else { var el = new System.Windows.Controls.Image() { Source = img, SnapsToDevicePixels = true, UseLayoutRounding = true, MinWidth = m_messageQueue.Device.Width, MinHeight = m_messageQueue.Device.Height, Width = img.Width * ((BitmapSource)img).DpiX / 96, Stretch = Stretch.UniformToFill, }; RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.NearestNeighbor); el.Measure(new Size(m_messageQueue.Device.Width, m_messageQueue.Device.Height)); el.Arrange(new Rect(0, 0, m_messageQueue.Device.Width, m_messageQueue.Device.Height)); m_messageQueue.Enqueue(new LedBadgeLib.MessageQueueItem(new LedBadgeLib.WpfVisual(m_messageQueue.Device, el, dither: Dither))); }; }
public void SendText(string text, Layout layout) { var lines = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); switch (layout) { case Layout.SingleLine: { for (int i = 0; i < lines.Length; ++i) { var msg = lines[i]; m_messageQueue.Enqueue(LedBadgeLib.WPF.MakeQueuedItem(m_messageQueue.Device, LedBadgeLib.WPF.MakeSingleLineItem(m_messageQueue.Device, msg))); } break; } case Layout.DoubleLine: { for (int i = 0; i < lines.Length; i += 2) { var msg1 = lines[i]; var msg2 = i + 1 < lines.Length ? lines[i + 1] : ""; m_messageQueue.Enqueue(LedBadgeLib.WPF.MakeQueuedItem(m_messageQueue.Device, LedBadgeLib.WPF.MakeDoubleLineItem(m_messageQueue.Device, msg1, msg2))); } break; } case Layout.Split: { for (int i = 0; i < lines.Length; i += 3) { var msg1 = lines[i]; var msg2 = i + 1 < lines.Length ? lines[i + 1] : ""; var msg3 = i + 2 < lines.Length ? lines[i + 2] : ""; m_messageQueue.Enqueue(LedBadgeLib.WPF.MakeQueuedItem(m_messageQueue.Device, LedBadgeLib.WPF.MakeSplitLineItem(m_messageQueue.Device, msg1, msg2, msg3))); } break; } } }