Пример #1
0
        private async void Enqueue(Uri uri, string namebase, Mediatype type, Geoposition position, string extension = null)
        {
            DebugUtil.Log("ContentsDownloader: Enqueue " + uri.AbsolutePath);

            if (extension == null)
            {
                var split = uri.AbsolutePath.Split('.');
                if (split.Length > 0)
                {
                    extension = "." + split[split.Length - 1].ToLower();
                    DebugUtil.Log("detected file extension: " + extension);
                }
            }

            await SystemUtil.GetCurrentDispatcher().RunAsync(CoreDispatcherPriority.Low, () =>
            {
                var req = new DownloadRequest
                {
                    Uri         = uri,
                    NameBase    = namebase,
                    Completed   = OnFetched,
                    Error       = OnFailed,
                    GeoPosition = position,
                    Mediatype   = type,
                    extension   = extension
                };
                DownloadQueue.Enqueue(req);
                QueueStatusUpdated.Raise(DownloadQueue.Count);
                ProcessQueueSequentially();
            });
        }
Пример #2
0
        public static async Task SetAsBitmap(byte[] data, ImageDataSource target, HistogramCreator Histogram, CoreDispatcher Dispatcher = null)
        {
            using (var stream = new InMemoryRandomAccessStream())
            {
                await stream.WriteAsync(data.AsBuffer());

                stream.Seek(0);
                if (Dispatcher == null)
                {
                    Dispatcher = SystemUtil.GetCurrentDispatcher();
                }
                if (Dispatcher == null)
                {
                    return;
                }

                await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                {
                    var image = new BitmapImage();
                    image.SetSource(stream);
                    target.Image = image;
                });

                if (Histogram == null)
                {
                    return;
                }

                if (ApplicationSettings.GetInstance().IsHistogramDisplayed&& !Histogram.IsRunning)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        Histogram.IsRunning = true;
                        stream.Seek(0);
                        var image = new BitmapImage();
                        image.SetSource(stream);
                        var writableImage = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
                        stream.Seek(0);
                        writableImage.SetSource(stream);
                        Histogram.CreateHistogram(writableImage);
                    });
                }
                else if (Histogram.IsRunning)
                {
                    DebugUtil.Log("Histogram creating. skip.");
                }
            }
        }