示例#1
0
        /// <summary>
        /// Asynchronously saves all the album arts in the library.
        /// </summary>
        /// <param name="Data">ID3 tag of the song to get album art data from.</param>
        public static async Task <bool> SaveImagesAsync(Windows.Storage.FileProperties.StorageItemThumbnail thumb, Mediafile file)
        {
            var albumartFolder = ApplicationData.Current.LocalFolder;
            var md5Path        = (file.Album + file.LeadArtist).ToLower().ToSha1();

            if (!File.Exists(albumartFolder.Path + @"\AlbumArts\" + md5Path + ".jpg"))
            {
                try
                {
                    Windows.Storage.Streams.IBuffer buf;
                    Windows.Storage.Streams.Buffer  inputBuffer = new Windows.Storage.Streams.Buffer(1024);
                    var albumart = await albumartFolder.CreateFileAsync(@"AlbumArts\" + md5Path + ".jpg", CreationCollisionOption.FailIfExists).AsTask().ConfigureAwait(false);

                    using (Windows.Storage.Streams.IRandomAccessStream albumstream = await albumart.OpenAsync(FileAccessMode.ReadWrite).AsTask().ConfigureAwait(false))
                    {
                        while ((buf = (await thumb.ReadAsync(inputBuffer, inputBuffer.Capacity, Windows.Storage.Streams.InputStreamOptions.None).AsTask().ConfigureAwait(false))).Length > 0)
                        {
                            await albumstream.WriteAsync(buf).AsTask().ConfigureAwait(false);
                        }
                    }

                    thumb.Dispose();
                    return(true);
                }
                catch (Exception ex)
                {
                    await NotificationManager.ShowAsync(ex.Message + "||" + file.Path);

                    return(false);
                }
            }
            return(false);
        }
示例#2
0
        async Task SetCurrentPlayingAsync(int playlistIndex)
        {
            string errorMessage = null;

            wasPlaying = MediaControl.IsPlaying;
            Windows.Storage.Streams.IRandomAccessStream stream = null;

            try
            {
                stream = await playlist[playlistIndex].File.OpenAsync(Windows.Storage.FileAccessMode.Read);
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { mediaElement.SetSource(stream, playlist[playlistIndex].File.ContentType); });
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }

            if (errorMessage != null)
            {
                await dispatchMessage("Error" + errorMessage);
            }


            MediaControl.ArtistName = playlist[playlistIndex].Artist;
            MediaControl.TrackName  = playlist[playlistIndex].Track;
        }
示例#3
0
        /// <summary>
        /// 通过FilePicker获取富文本流(弹出框选文件)
        /// </summary>
        /// <returns>富文本流</returns>
        public async Task <IRandomAccessStream> GetRandomAccessStream()
        {
            Windows.Storage.Pickers.FileOpenPicker open =
                new Windows.Storage.Pickers.FileOpenPicker();
            open.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            open.FileTypeFilter.Add(".rtf");

            Windows.Storage.StorageFile file = await open.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    Windows.Storage.Streams.IRandomAccessStream randAccStream =
                        await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    // Load the file into the Document property of the RichEditBox.
                    return(randAccStream);
                }
                catch (Exception)
                {
                    ContentDialog errorDialog = new ContentDialog()
                    {
                        Title             = "File open error",
                        Content           = "Sorry, I couldn't open the file.",
                        PrimaryButtonText = "Ok"
                    };

                    await errorDialog.ShowAsync();
                }
            }
            return(null);
        }
        async void PickFile(object sender, RoutedEventArgs e)
        {
            var currentState = Windows.UI.ViewManagement.ApplicationView.Value;

            if (currentState == Windows.UI.ViewManagement.ApplicationViewState.Snapped && !Windows.UI.ViewManagement.ApplicationView.TryUnsnap())
            {
                TranscodeError("Cannot pick files while application is in snapped view");
            }
            else
            {
                Windows.Storage.Pickers.FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
                picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
                picker.FileTypeFilter.Add(".wmv");
                picker.FileTypeFilter.Add(".mp4");

                Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

                if (file != null)
                {
                    Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    _InputFile = file;
                    InputVideo.SetSource(stream, file.ContentType);
                    InputVideo.Play();

                    // Enable buttons
                    EnableButtons();
                }
            }
        }
示例#5
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(fileStream);

                    bitmapImageEx = await new WriteableBitmap(1, 1).FromStream(fileStream);

                    WidthControl.Text = bitmapImageEx.PixelWidth.ToString();

                    Resize();

                    R1.IsChecked = true;
                }
            }
        }
        private async void open_btn_Click(object sender, RoutedEventArgs e)
        {
            // Open a text file.
            Windows.Storage.Pickers.FileOpenPicker open = new Windows.Storage.Pickers.FileOpenPicker();
            open.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            open.FileTypeFilter.Add(".rtf");

            Windows.Storage.StorageFile file = await open.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    Windows.Storage.Streams.IRandomAccessStream randAccStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    // Load the file into the Document property of the RichEditBox.
                    editBox.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, randAccStream);
                }
                catch (Exception)
                {
                    ContentDialog errorDialog = new ContentDialog()
                    {
                        Title             = "File open error",
                        Content           = "Sorry, I couldn't open the file.",
                        PrimaryButtonText = "Ok"
                    };

                    await errorDialog.ShowAsync();
                }
            }
        }
示例#7
0
        private async void SaveButtonPressed(object sender, PointerRoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker();
            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Rich Text", new List <string>()
            {
                ".rtf"
            });

            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "New Document";

            Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                // Prevent updates to the remote version of the file until we
                // finish making changes and call CompleteUpdatesAsync.
                Windows.Storage.CachedFileManager.DeferUpdates(file);
                // write to file
                Windows.Storage.Streams.IRandomAccessStream randAccStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                TxtArea.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream);
                Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);
            }
        }
        public async void OdabirSlikeAsync(object parameter)
        {
            var IzbornikSlike = new Windows.Storage.Pickers.FileOpenPicker
            {
                ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
            };

            IzbornikSlike.FileTypeFilter.Add(".jpg");
            IzbornikSlike.FileTypeFilter.Add(".jpeg");
            IzbornikSlike.FileTypeFilter.Add(".png");
            Windows.Storage.StorageFile Slika = await IzbornikSlike.PickSingleFileAsync();

            if (Slika == null)
            {
                MessageDialog greska = new MessageDialog("Greška pri odabiru slike!");
                greska.ShowAsync();
                return;
            }
            else
            {
                using (Windows.Storage.Streams.IRandomAccessStream fileStream = await Slika.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    Windows.UI.Xaml.Media.Imaging.BitmapImage SlikaBitMapa = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    SlikaBitMapa.SetSource(fileStream);
                    PathSlike = Convert.ToString(fileStream);
                }
            }
        }
示例#9
0
        private async void UploadPic2(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                //imagePath.Text = file.Path;
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(fileStream);
                    uploadedImage2.Source = bitmapImage;
                    Button2.Visibility    = Visibility.Collapsed;
                    pic2 = true;

                    if (pic1 && pic2)
                    {
                        MixBtn.Visibility = Visibility.Visible;
                    }
                }
            }
        }
示例#10
0
        private async void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker filepicker = new Windows.Storage.Pickers.FileOpenPicker();
            filepicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            filepicker.FileTypeFilter.Add(".jpg");
            filepicker.FileTypeFilter.Add(".png");
            filepicker.FileTypeFilter.Add(".bmp");
            filepicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            Windows.Storage.StorageFile imageFile = await filepicker.PickSingleFileAsync();

            if (imageFile != null)
            {
                Windows.UI.Xaml.Media.Imaging.BitmapImage   bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                Windows.Storage.Streams.IRandomAccessStream stream = await imageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                Image newImage = new Image();
                bitmap.SetSource(stream);
                newImage.Source = bitmap;
                //newImage.Height = 250;
                newImage.Stretch          = Stretch.UniformToFill;
                newImage.ManipulationMode = ManipulationModes.All;

                this.MyCanvas.Children.Add(newImage);
            }
        }
示例#11
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            StorageFile floorPlanFile = await _curDataset.Folder.GetFileAsync(_curDataset.pathToFloorPlan);

            using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                       await floorPlanFile.OpenAsync(FileAccessMode.Read))
            {
                // Set the image source to the selected bitmap.
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(fileStream);
                floorplanImage.Source = bitmapImage;
            }
            PopulateSensors();
            DrawSensors();
            sensorDetail.IsReadOnly   = true;
            sensorDetail.Text         = "";
            sensorDetail.TextWrapping = TextWrapping.Wrap;
            sensorDetail.Background   = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
            sensorDetail.Opacity      = 0.998;
            sensorDetail.Width        = 200;
            sensorDetail.Visibility   = Visibility.Collapsed;
            Canvas.SetZIndex(sensorDetail, 101);
            sensorCanvas.Children.Add(sensorDetail);

            // VertialSplitter Move Control
            VerticalSplitter.ManipulationMode   = ManipulationModes.All;
            VerticalSplitter.ManipulationDelta += VerticalSplitter_ManipulationDelta;
        }
示例#12
0
        public async Task <SoftwareBitmap> CreateSoftwareBitmap(Windows.Storage.StorageFile file, BitmapImage bitmap)
        {
            Windows.Storage.Streams.IRandomAccessStream random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(file).OpenReadAsync();

            Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);

            var swBitmap = new SoftwareBitmap(BitmapPixelFormat.Rgba8, bitmap.PixelWidth, bitmap.PixelHeight);

            return(swBitmap = await decoder.GetSoftwareBitmapAsync());
        }
示例#13
0
        public static async Task <byte[]> ImageToByteArray(Uri uri)
        {
            Windows.Storage.Streams.IRandomAccessStream random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(uri).OpenReadAsync();

            Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);

            Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync();

            return(pixelData.DetachPixelData());
        }
示例#14
0
        public async void DrawFaceRectangle(Emotion[] emotionResult, BitmapImage bitMapImage, String urlString)
        {
            if (emotionResult != null && emotionResult.Length > 0)
            {
                Windows.Storage.Streams.IRandomAccessStream stream = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri(urlString)).OpenReadAsync();


                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);


                double resizeFactorH = ImageCanvas.Height / decoder.PixelHeight;
                double resizeFactorW = ImageCanvas.Width / decoder.PixelWidth;


                foreach (var emotion in emotionResult)
                {
                    Microsoft.ProjectOxford.Common.Rectangle faceRect = emotion.FaceRectangle;

                    Image       Img    = new Image();
                    BitmapImage BitImg = new BitmapImage();
                    // open the rectangle image, this will be our face box
                    Windows.Storage.Streams.IRandomAccessStream box = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/rectangle.png", UriKind.Absolute)).OpenReadAsync();

                    BitImg.SetSource(box);

                    //rescale each facebox based on the API's face rectangle
                    var maxWidth  = faceRect.Width * resizeFactorW;
                    var maxHeight = faceRect.Height * resizeFactorH;

                    var origHeight = BitImg.PixelHeight;
                    var origWidth  = BitImg.PixelWidth;


                    var ratioX    = maxWidth / (float)origWidth;
                    var ratioY    = maxHeight / (float)origHeight;
                    var ratio     = Math.Min(ratioX, ratioY);
                    var newHeight = (int)(origHeight * ratio);
                    var newWidth  = (int)(origWidth * ratio);

                    BitImg.DecodePixelWidth  = newWidth;
                    BitImg.DecodePixelHeight = newHeight;

                    // set the starting x and y coordiantes for each face box
                    Thickness margin = Img.Margin;

                    margin.Left = faceRect.Left * resizeFactorW;
                    margin.Top  = faceRect.Top * resizeFactorH;

                    Img.Margin = margin;

                    Img.Source = BitImg;
                    ImageCanvas.Children.Add(Img);
                }
            }
        }
示例#15
0
        private async void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");

            // Open the file picker.
            Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

            // file is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                displayImage.Source = bitmapImage;

                this.DataContext = file;
            }

            try
            {
                var db     = new SQLite.SQLiteConnection(App.DBPath);
                var emptab = (db.Table <lawyer>().Where(em => em.username == txt1.Text)).Single();

                var targetFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(emptab.username + ".jpg");

                if (targetFile != null)
                {
                    //await file.MoveAndReplaceAsync(targetFile);
                    await file.CopyAndReplaceAsync(targetFile);
                }
            }
            catch (Exception ex)
            {
                var var_name = new MessageDialog("Unable to update profile picture\nPlease try after sometime.");
                var_name.Commands.Add(new UICommand("OK"));
                var_name.ShowAsync();
            }

            // await file.CopyAsync(ApplicationData.Current.LocalFolder);
        }
示例#16
0
        /// <summary>
        /// 打开并导入rtf文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Streams.IRandomAccessStream randAccStream =
                await ServiceLocator.Instance.Resolve <FileService>().GetRandomAccessStream();

            if (randAccStream != null)
            {
                // Load the file into the Document property of the RichEditBox.
                editor.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, randAccStream);
            }
        }
示例#17
0
        public static async Task <byte[]> GetBytesAsync(this storage.StorageFile file)
        {
            sStream.IRandomAccessStream fileStream = await file.OpenAsync(storage.FileAccessMode.Read);

            var reader = new sStream.DataReader(fileStream.GetInputStreamAt(0));
            await reader.LoadAsync((uint)fileStream.Size);

            byte[] bytes = new byte[fileStream.Size];
            reader.ReadBytes(bytes);
            return(bytes);
        }
示例#18
0
        Image[,] winCombo = new Image[4, 4];        //winning combination


        //Lets the user choose an image from the local drive. If an image is chosen, a timer is started.
        //Also, this method calls the PlaceImg method to cut and shuffle.
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            loser.Visibility  = Visibility.Collapsed;
            winner.Visibility = Visibility.Collapsed;
            // Set up the file picker.
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");
            Error.Visibility = Visibility.Collapsed;
            // Open the file picker.
            Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

            // 'file' is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                // The 'using' block ensures the stream is disposed
                // after the image is loaded.
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    image1.Source = bitmapImage;
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);

                    PlaceImg(decoder);
                }
                play            = true;
                Timer1          = new Windows.UI.Xaml.DispatcherTimer();
                Timer1.Interval = TimeSpan.FromMilliseconds(1000);
                Timer1.Tick    += Timer1_Tick;
                if (Timer1.IsEnabled)
                {
                    Timer1.Stop();
                }
                Timer1.Start();
                time = GameTime;

                Choose.IsEnabled  = false;
                Capture.IsEnabled = false;
            }
        }
示例#19
0
 public async void initValue()
 {
     musicList.Clear();
     await getFiles(musicList, folder);
     STT = 0;
     musicProperties = null;
     stream = null;
     state = MediaState.STOP;
     pb = Playback.ORDER;
     rp = Repeat.ALL;
     nof = NumOfLoad.FIRST;
 }
        private async void save_btn_Click(object sender, RoutedEventArgs e)
        {
            string document;

            //Get the text and put it in the "document" var, can then use it as a string of text!
            editBox.Document.GetText(Windows.UI.Text.TextGetOptions.AdjustCrlf, out document);
            if (!string.IsNullOrEmpty(document))
            {
                Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker();
                savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

                // Dropdown of file types the user can save the file as
                savePicker.FileTypeChoices.Add("Rich Text", new List <string>()
                {
                    ".rtf"
                });

                // Default file name if the user does not type one in or select a file to replace
                savePicker.SuggestedFileName = "New Document";

                Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

                if (file != null)
                {
                    // Prevent updates to the remote version of the file until we
                    // finish making changes and call CompleteUpdatesAsync.
                    Windows.Storage.CachedFileManager.DeferUpdates(file);
                    // write to file
                    Windows.Storage.Streams.IRandomAccessStream randAccStream =
                        await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                    editBox.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream);

                    // Let Windows know that we're finished changing the file so the
                    // other app can update the remote version of the file.
                    Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

                    if (status != Windows.Storage.Provider.FileUpdateStatus.Complete)
                    {
                        Windows.UI.Popups.MessageDialog errorBox =
                            new Windows.UI.Popups.MessageDialog("File " + file.Name + " couldn't be saved.");
                        await errorBox.ShowAsync();
                    }
                }
            }
            else
            {
                Windows.UI.Popups.MessageDialog error = new Windows.UI.Popups.MessageDialog("There is nothing to save!!!");
                await error.ShowAsync();
            }
        }
        async void TranscodeComplete()
        {
            OutputText("Transcode completed.");
            OutputPathText("Output (" + _OutputFile.Path + ")");
            Windows.Storage.Streams.IRandomAccessStream stream = await _OutputFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

            await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                OutputVideo.SetSource(stream, _OutputFile.ContentType);
            });

            EnableButtons();
            SetCancelButton(false);
        }
示例#22
0
        public async Task LoadAsync(Windows.Storage.Streams.IRandomAccessStream stream, string filename)
        {
            try
            {
                Content = await pdf.PdfDocument.LoadFromStreamAsync(stream);

                OnLoaded();
                ID = Helper.Functions.CombineStringAndDouble(filename, Content.PageCount);
            }
            catch
            {
                Content = null;
            }
        }
        private SpeechToTextMainStream(ulong MaxSizeInBytes = 0, uint ThresholdDuration = 0, uint ThresholdLevel = 0)
        {
            tresholdDuration         = ThresholdDuration;
            thresholdDurationInBytes = 0;
            thresholdLevel           = ThresholdLevel;
            maxSize = MaxSizeInBytes;

            thresholdStart = 0;
            thresholdEnd   = 0;
            audioStream    = null;
            internalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
            inputStream    = internalStream.GetInputStreamAt(0);
            audioQueue     = new ConcurrentQueue <SpeechToTextAudioStream>();
        }
 async void PlayFile(Windows.Storage.StorageFile MediaFile)
 {
     await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
     {
         try
         {
             Windows.Storage.Streams.IRandomAccessStream stream = await MediaFile.OpenAsync(FileAccessMode.Read);
             OutputVideo.SetSource(stream, MediaFile.ContentType);
             OutputVideo.Play();
         }
         catch (Exception exception)
         {
             TranscodeError(exception.Message);
         }
     });
 }
示例#25
0
        private async Task <Windows.Storage.StorageFile> ReencodePhotoAsync(Windows.Storage.StorageFile tempStorageFile, Windows.Storage.FileProperties.PhotoOrientation photoRotation)
        {
            Windows.Storage.Streams.IRandomAccessStream inputStream  = null;
            Windows.Storage.Streams.IRandomAccessStream outputStream = null;
            Windows.Storage.StorageFile photoStorage = null;

            try
            {
                String newPhotoFilename = photoId + "_" + photoCount.ToString() + ".jpg";

                inputStream = await tempStorageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(inputStream);

                photoStorage = await currentFolder.CreateFileAsync(newPhotoFilename, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                outputStream = await photoStorage.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                outputStream.Size = 0;

                var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);

                var properties = new Windows.Graphics.Imaging.BitmapPropertySet();
                properties.Add("System.Photo.Orientation", new Windows.Graphics.Imaging.BitmapTypedValue(photoRotation, Windows.Foundation.PropertyType.UInt16));

                await encoder.BitmapProperties.SetPropertiesAsync(properties);

                await encoder.FlushAsync();
            }
            finally
            {
                if (inputStream != null)
                {
                    inputStream.Dispose();
                }

                if (outputStream != null)
                {
                    outputStream.Dispose();
                }

                var asyncAction = tempStorageFile.DeleteAsync(Windows.Storage.StorageDeleteOption.PermanentDelete);
            }

            return(photoStorage);
        }
示例#26
0
        private SpeechToTextAudioStream(
            uint Channels,
            uint SamplesPerSec,
            uint AvgBytesPerSec,
            uint BlockAlign,
            uint BitsPerSample,
            ulong AudioStart)
        {
            nChannels       = Channels;
            nSamplesPerSec  = SamplesPerSec;
            nAvgBytesPerSec = AvgBytesPerSec;
            nBlockAlign     = BlockAlign;
            wBitsPerSample  = BitsPerSample;
            audioStart      = AudioStart;


            internalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
            inputStream    = internalStream.GetInputStreamAt(0);
        }
        async Task <BitmapSource> resize(int width, int height, Windows.Storage.Streams.IRandomAccessStream source)
        {
            WriteableBitmap small   = new WriteableBitmap(width, height);
            BitmapDecoder   decoder = await BitmapDecoder.CreateAsync(source);

            BitmapTransform transform = new BitmapTransform();

            transform.ScaledHeight = (uint)height;
            transform.ScaledWidth  = (uint)width;
            PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
                BitmapPixelFormat.Bgra8,
                BitmapAlphaMode.Straight,
                transform,
                ExifOrientationMode.RespectExifOrientation,
                ColorManagementMode.DoNotColorManage);

            pixelData.DetachPixelData().CopyTo(small.PixelBuffer);
            return(small);
        }
        async void Save(Stream stream, string filename, string type)
        {
            stream.Position = 0;

            StorageFile stFile;

            if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")))
            {
                FileSavePicker savePicker = new FileSavePicker();
                savePicker.DefaultFileExtension = type;
                savePicker.SuggestedFileName    = filename.Substring(0, filename.IndexOf("."));
                if (type == ".pdf")
                {
                    savePicker.FileTypeChoices.Add("Adobe PDF Document", new List <string>()
                    {
                        type
                    });
                }
                else
                {
                    savePicker.FileTypeChoices.Add("JPG", new List <string>()
                    {
                        type
                    });
                }
                stFile = await savePicker.PickSaveFileAsync();
            }
            else
            {
                StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
                stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
            }
            if (stFile != null)
            {
                Windows.Storage.Streams.IRandomAccessStream fileStream = await stFile.OpenAsync(FileAccessMode.ReadWrite);

                Stream st = fileStream.AsStreamForWrite();
                st.Write((stream as MemoryStream).ToArray(), 0, (int)stream.Length);
                st.Flush();
                st.Dispose();
                fileStream.Dispose();
            }
        }
        async void PickFile(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
            picker.FileTypeFilter.Add(".wmv");
            picker.FileTypeFilter.Add(".mp4");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                _InputFile = file;
                InputVideo.SetSource(stream, file.ContentType);
                InputVideo.Play();

                // Enable buttons
                EnableButtons();
            }
        }
示例#30
0
        /// <summary>
        /// 设置富文本框的内容流
        /// </summary>
        /// <param name="editor">富文本框</param>
        public async Task SetRandomAccessStream(RichEditBox editor)
        {
            Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker();
            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Rich Text", new List <string>()
            {
                ".rtf"
            });

            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "New Document";

            Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                // Prevent updates to the remote version of the file until we
                // finish making changes and call CompleteUpdatesAsync.
                Windows.Storage.CachedFileManager.DeferUpdates(file);
                // write to file
                Windows.Storage.Streams.IRandomAccessStream randAccStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                editor.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream);


                // Let Windows know that we're finished changing the file so the
                // other app can update the remote version of the file.
                Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

                if (status != Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    Windows.UI.Popups.MessageDialog errorBox =
                        new Windows.UI.Popups.MessageDialog("File " + file.Name + " couldn't be saved.");
                    await errorBox.ShowAsync();
                }
            }
        }
示例#31
0
        private async void button3_Click(object sender, RoutedEventArgs e)
        {
            // Create FileOpenPicker instance
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            // Set SuggestedStartLocation
            fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

            // Set ViewMode
            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;

            // Filter for file types. For example, if you want to open text files,
            // you will add .txt to the list.

            fileOpenPicker.FileTypeFilter.Clear();
            fileOpenPicker.FileTypeFilter.Add(".png");
            fileOpenPicker.FileTypeFilter.Add(".jpeg");
            fileOpenPicker.FileTypeFilter.Add(".jpg");
            fileOpenPicker.FileTypeFilter.Add(".bmp");

            // Open FileOpenPicker
            StorageFile file = await fileOpenPicker.PickSingleFileAsync();

            if (file != null)
            {
                FileNameTextBlock = file.Name;
                // Open a stream
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(FileAccessMode.Read);

                // Create a BitmapImage and Set stream as source
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(fileStream);

                // Set BitmapImage Source
                ImageViewer = bitmapImage;
            }
        }
示例#32
0
 public async void getProperties_accessStream(int nOfSTT)
 {
     var audioFile = await folder.GetFileAsync(musicList[nOfSTT].Name);
     musicProperties = await audioFile.Properties.GetMusicPropertiesAsync();
     stream = await audioFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
 }