예제 #1
0
        private async Task <bool> ApplyEffectAsync(StorageFile file)
        {
            if (CurrentSelectedEffect == null && CurrentSelectedEffect.Effect == null)
            {
                return(false);
            }
            // Open a stream for the selected file.
            IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

            string errorMessage = null;

            try
            {
                // Rewind stream to start.
                fileStream.Seek(0);

                // A cartoon effect is initialized with selected image stream as source.
                var imageStream = new Lumia.Imaging.RandomAccessStreamImageSource(fileStream);
                UpdateCustomEffectSource(imageStream);
                ((IImageConsumer)CurrentSelectedEffect.Effect).Source = imageStream;
                await RenderAsync();
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                var dialog = new MessageDialog(errorMessage);
                await dialog.ShowAsync();

                return(false);
            }

            return(true);
        }
        private async Task<bool> ApplyEffectAsync(StorageFile file)
        {

            if (CurrentSelectedEffect == null && CurrentSelectedEffect.Effect == null)
            {
                return false;
            }
            // Open a stream for the selected file.
            IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);
            string errorMessage = null;

            try
            {
                // Rewind stream to start.                     
                fileStream.Seek(0);

                // A cartoon effect is initialized with selected image stream as source.
                var imageStream = new Lumia.Imaging.RandomAccessStreamImageSource(fileStream);
                UpdateCustomEffectSource(imageStream);
                ((IImageConsumer)CurrentSelectedEffect.Effect).Source = imageStream;
                await RenderAsync();

            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                var dialog = new MessageDialog(errorMessage);
                await dialog.ShowAsync();
                return false;
            }

            return true;
        }