/// <summary> /// De pdf's worden toegevoegd aan het Stackpanel /// </summary> /// <param name="pdfNaam">De naam van de PDF van het type string</param> /// <returns>Task</returns> private async Task VoegPdfToeAanBijlagen(string pdfNaam) { try { var afbeeldingen = await HaalPdfAfbeeldingenOp(pdfNaam); foreach (StorageFile pagina in afbeeldingen) { //Scrollview voor een afbeelding var scroll = new ScrollViewer(); scroll.HorizontalScrollMode = ScrollMode.Auto; scroll.VerticalScrollMode = ScrollMode.Auto; scroll.ZoomMode = ZoomMode.Enabled; BitmapImage paginaAfbeelding = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await pagina.OpenAsync(FileAccessMode.Read); paginaAfbeelding.SetSource(stream); Image paginaAfbeeldingControl = new Image(); paginaAfbeeldingControl.Source = paginaAfbeelding; paginaAfbeeldingControl.Tapped += ImgWagenmap_Tapped; scroll.Content = paginaAfbeeldingControl; wagenMapPanel.Children.Add(scroll); } } catch (Exception ex) { paLogging.log.Error(String.Format("De afbeelding kon niet getoond worden op het bijlagenscherm.\n{0}", ex.Message)); } }
public async Task <List <Image> > GetDiskImagesAsync(StorageFolder picturesFolder) { List <Image> imagens = new List <Image>(); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async() => { IReadOnlyList <IStorageItem> itemsList = await picturesFolder.GetFilesAsync(); foreach (var item in itemsList) { await picturesFolder.TryGetItemAsync(item.Name); if (item.Path.Contains(".jpg") || item.Path.Contains(".png")) { var uri = new System.Uri(item.Path); var converted = uri.AbsoluteUri; StorageFile file = await picturesFolder.GetFileAsync(item.Name); BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); Image image = new Image(); image.Name = item.Name; image.Source = bitmapImage; imagens.Add(image); } } }); return(imagens); }
/// <summary> /// Deze methode toont een PDF op het scherm. Dit door een PDF om te zetten naar een afbeelding /// </summary> /// <param name="pdfNaam">naam van de PDF van het type String</param> /// <returns>Task</returns> private async Task VoegPdfToeAanBijlagen(string pdfNaam) { try { var afbeeldingen = await PdfSupport.pdfSupport.HaalPdfAfbeeldingenOp(storageFolders, pdfNaam); TextBlock txtPdfTitel = new TextBlock(); txtPdfTitel.Text = pdfNaam; txtPdfTitel.FontSize = 40; txtPdfTitel.TextAlignment = TextAlignment.Center; txtPdfTitel.Width = bijlagenGrid.Width - 20; txtPdfTitel.Margin = new Thickness(10, 70, 10, 10); bijlagenPanel.Children.Add(txtPdfTitel); foreach (StorageFile pagina in afbeeldingen) { BitmapImage paginaAfbeelding = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await pagina.OpenAsync(FileAccessMode.Read); paginaAfbeelding.SetSource(stream); Image paginaAfbeeldingControl = new Image(); paginaAfbeeldingControl.Source = paginaAfbeelding; paginaAfbeeldingControl.Tapped += ImgBijlage_Tapped; bijlagenPanel.Children.Add(paginaAfbeeldingControl); } } catch (Exception ex) { paLogging.log.Error(String.Format("Een van de afbeeldingen kon niet getoond worden op het bijlagenscherm.\n{0}", ex.Message)); } }
private async void LoadImage(StorageFile file) { ImageSource = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); ImageSource.SetSource(stream); }
private async void Button_Upload_Image(object sender, RoutedEventArgs e) { FileOpenPicker picker = new FileOpenPicker(); picker.ViewMode = PickerViewMode.Thumbnail; picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { // Application now has read/write access to the picked file try { BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); image.Source = bitmapImage; } catch (Exception) { MessageDialog msg = new MessageDialog("发生了些小问题,稍后试试吧", "Oops!"); await msg.ShowAsync(); } } }
private async void BtnTake_Click(object sender, RoutedEventArgs e) { CameraCaptureUI capture = new CameraCaptureUI(); capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; StorageFile file = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file != null) { StorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Album", CreationCollisionOption.OpenIfExists); string fileName = DateTime.Now.Ticks + ".jpg"; await file.CopyAsync(folder, fileName, NameCollisionOption.ReplaceExisting); await file.DeleteAsync(); file = await folder.GetFileAsync(fileName); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); BitmapImage image = new BitmapImage(); image.SetSource(stream); Photo.Source = image; } }
private async void ContentDialog_TakePhoto_Clicked(object sender, RoutedEventArgs e) { CameraCaptureUI captureUI = new CameraCaptureUI(); captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; captureUI.PhotoSettings.AllowCropping = false; StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo); if (photo == null) { // User cancelled photo capture return; } // Otherwise we need to save the temporary file (after doing some clean up if we already have a file) if (TemporaryFile != null) { await TemporaryFile.DeleteAsync(); } // Save off the photo TemporaryFile = photo; // Update the image BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await TemporaryFile.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); image.Source = bitmapImage; }
private async void Button_Upload_Image(object sender, RoutedEventArgs e) // 上传图片的事件 { FileOpenPicker picker = new FileOpenPicker(); picker.ViewMode = PickerViewMode.Thumbnail; picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); StorageFile file = await picker.PickSingleFileAsync(); TodoItemViewModel.ImageName = file.Name; // 获取文件名 if (file != null) { ApplicationData.Current.LocalSettings.Values["image"] = StorageApplicationPermissions.FutureAccessList.Add(file); // 挂起时保存图片 try { BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); image.Source = bitmapImage; } catch (Exception) { MessageDialog msg = new MessageDialog("发生了些小问题,稍后试试吧", "Oops!"); await msg.ShowAsync(); } } }
public static async Task <PeriodicTable> LoadTable() { PeriodicTable aTable = null; try { StorageFile sf = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Chemistry.Elements\XML\Elements.xml"); //Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("PeriodicTable.test.xml"); //XmlDocument doc = new XmlDocument(); //doc.Load(s); // FileStream fs = new FileStream(@"C:\test.xml", FileMode.Open, FileAccess.Read); Type t = typeof(PeriodicTable); XmlSerializer ser = new XmlSerializer(typeof(PeriodicTable)); FileRandomAccessStream stream = (FileRandomAccessStream)await sf.OpenAsync(FileAccessMode.Read); System.IO.Stream st = stream.AsStreamForRead(); aTable = (PeriodicTable)ser.Deserialize(st); } catch (Exception e) { string s = e.Message; aTable = new PeriodicTable(); } foreach (ChemElement e in aTable.Elements) { e.CreatePropertyList(); } return(aTable); }
public async Task <BitmapImage> GetAvatar() { StorageFolder localFolder = ApplicationData.Current.TemporaryFolder; BitmapImage avatar = new BitmapImage(); //On tente de récupérer l'avatar sur la mémoire locale try { StorageFile avatarFile = await localFolder.GetFileAsync(pseudo + "_avatar.png"); FileRandomAccessStream stream = (FileRandomAccessStream)await avatarFile.OpenAsync(FileAccessMode.Read); avatar.SetSource(stream); } //Sinon, on le télécharge catch (Exception) { // Avatar not found not found. var bufferAvatar = await Resources.APIWebTeam.UserManagement.GetUserImageAsyncAsBuffer(id); StorageFile avatarFile = await localFolder.CreateFileAsync(pseudo + "_avatar.png", CreationCollisionOption.ReplaceExisting); await FileIO.WriteBufferAsync(avatarFile, bufferAvatar); FileRandomAccessStream stream = (FileRandomAccessStream)await avatarFile.OpenAsync(FileAccessMode.Read); avatar.SetSource(stream); } return(avatar); }
public async void StartGame() { if (progressRing.IsActive == false) { progressRing.IsActive = true; if (GameGlobal.PictrueSource == null && string.IsNullOrEmpty(IsGallery) || !IsPictureSelected && string.IsNullOrEmpty(IsGallery)) { var bmp = (TempBorder.Child as Image).Source as BitmapImage; StorageFile file = GetFileFromUriAsync(bmp.UriSource.OriginalString); if (file != null) { using (FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read)) { var property = await file.Properties.GetImagePropertiesAsync(); WriteableBitmap wbm = new WriteableBitmap((int)property.Width, (int)property.Height); wbm.SetSource(stream); GameGlobal.PictrueSource = wbm; GameGlobal.CurrentUriSource = bmp.UriSource; stream.Dispose(); } } } GameGlobal.SetLevel(new Size(CountParts * K, CountParts)); progressRing.IsActive = false; Frame.Navigate(typeof(GameInterface)); } }
public static IEnumerable <string> ReadLines(string path) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException(); } try { IAsyncOperation <IRandomAccessStream> source = FileHelper.GetFileForPathOrURI(path).OpenAsync(FileAccessMode.Read); WindowsRuntimeSystemExtensions.AsTask <IRandomAccessStream>(source).Wait(); using (FileRandomAccessStream randomAccessStream = (FileRandomAccessStream)source.GetResults()) { StreamReader streamReader = new StreamReader(WindowsRuntimeStreamExtensions.AsStreamForRead((IInputStream)randomAccessStream)); List <string> list = new List <string>(); while (true) { string str = streamReader.ReadLine(); if (str != null) { list.Add(str); } else { break; } } return((IEnumerable <string>)list); } } catch (Exception ex) { throw File.GetRethrowException(ex); } }
private async void ProfilePictureBorder_DragOver(object sender, DragEventArgs e) { if (e.DataView.Contains(StandardDataFormats.StorageItems)) { var items = await e.DataView.GetStorageItemsAsync(); if (items.Count > 0) { //ProfileImage.ImageFile = items[0] as StorageFile; bitmapImage = new BitmapImage(); StorageFile storageFile = items[0] as StorageFile; FileRandomAccessStream stream = (FileRandomAccessStream)await storageFile.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); ProfileImage.ImageSource = bitmapImage; // 웹으로 이미지 변경 정보 전송 // For Testing //await Task.Delay(1000); } } }
private async void LoadTemplateImage(string answer) { this.currentImageTemplate = new BitmapImage(); StorageFile currentImageTemplateFile = templateImageFiles[answer]; FileRandomAccessStream stream = (FileRandomAccessStream)await currentImageTemplateFile.OpenAsync(FileAccessMode.Read); this.currentImageTemplate.SetSource(stream); }
public async Task <ImageSource> ConvertImage(StorageFile file) { var bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); return(bitmapImage); }
public async Task <BitmapImage> GetImageAsync(StorageFile storageFile) { BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await storageFile.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); return(bitmapImage); }
private static async Task <BitmapImage> MyLoadImage(StorageFile file) { BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); return(bitmapImage); }
// Load Image public static async Task <BitmapImage> LoadImage(StorageFile file) { BitmapImage source = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); source.SetSource(stream); return(source); }
public async Task <SoftwareBitmap> LoadStudyAsync(IInputStream stream) { FileRandomAccessStream fstream = (FileRandomAccessStream)stream; BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fstream); SoftwareBitmap softbitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); return(softbitmap); }
private async void MySubmitButton_Click(object sender, RoutedEventArgs e) { // save the sketch string currentLabel = Path.GetFileNameWithoutExtension(myImageFiles[Indexer - 1].Path); string fileName = currentLabel + "_" + DateTime.Now.Ticks + ".xml"; StorageFile currentFile = await mySaveFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);; List <InkStroke> currentStrokes = MyInkCanvas.InkPresenter.StrokeContainer.GetStrokes().ToList(); List <List <long> > currentTimeCollection = myTimeCollection; double frameMinX = 0; double frameMinY = 0; double frameMaxX = MyInkCanvas.ActualWidth; double frameMaxY = MyInkCanvas.ActualHeight; //WriteXml(currentFile, currentLabel, MyInkCanvas.InkPresenter.StrokeContainer.GetStrokes(), myTimeCollection); SketchTools.SketchToXml(currentFile, currentLabel, currentStrokes, currentTimeCollection, frameMinX, frameMinY, frameMaxX, frameMaxY); // clear and reset the sketch MyClearButton_Click(null, null); // stop the data collection if no more images left if (Indexer < myImageFiles.Count) { // display the next prompt string nextLabel = Path.GetFileNameWithoutExtension(myImageFiles[Indexer].Path); MyPromptText.Text = "Please draw the following: " + nextLabel; // display the next image StorageFile testFile = myImageFiles[Indexer]; BitmapImage bitmap = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await testFile.OpenAsync(FileAccessMode.Read); bitmap.SetSource(stream); MyImage.Source = bitmap; // increment the indexer to the next image ++Indexer; } else { MySubmitButton.IsEnabled = false; MessageDialog dialog = new MessageDialog("You have completed the data collection."); dialog.Commands.Add(new UICommand("Okay") { Id = 0 }); dialog.DefaultCommandIndex = 0; var result = await dialog.ShowAsync(); if ((int)result.Id == 0) { Application.Current.Exit(); } } }
public void Close() { if (!isClosed) { isClosed = true; stream.Dispose(); stream = null; fileStream.Dispose(); fileStream = null; } }
public virtual async Task <IRandomAccessStream> GetRandomAccessStreamFromFileAsync(FileAccessMode Mode) { if (StorageItem is StorageFile File) { return(await File.OpenAsync(Mode)); } else { return(await FileRandomAccessStream.OpenAsync(Path, Mode)); } }
/// <summary> /// Loads a new source into the player from a media data object. /// </summary> /// <param name="targetMedia">The object to provide for loading into the player.</param> private async void loadSource(List <NBMedia> targetMedias) { if (NBPlayerState.CurrentPlaylist != null) { NBPlayerState.CurrentPlaylist.CurrentItemChanged -= Playlist_CurrentItemChanged; } if (targetMedias[0].GetType() != typeof(NBImage)) { imgDisplayerFrame.Visibility = Visibility.Collapsed; medPlayer.Visibility = Visibility.Visible; MediaPlaybackList playlist = new MediaPlaybackList(); List <NBPlayableMedia> mediaList = new List <NBPlayableMedia>(); foreach (NBMedia media in targetMedias) { MediaSource source = MediaSource.CreateFromStorageFile(media.MediaFile); MediaPlaybackItem playbackItem = new MediaPlaybackItem(source); playbackItem.CanSkip = true; playlist.Items.Add(playbackItem); } NBPlayerState.CurrentMediaList = targetMedias; NBPlayerState.CurrentSourceIndex = 0; NBPlayerState.CurrentImage = null; playlist.CurrentItemChanged += Playlist_CurrentItemChanged; playlist.ItemFailed += Playlist_ItemFailed; NBPlayerState.CurrentPlaylist = playlist; currentMediaPlayer.Source = playlist; currentMediaPlayer.Play(); } else { medPlayer.Visibility = Visibility.Collapsed; FileRandomAccessStream stream = (FileRandomAccessStream)await targetMedias[0].MediaFile.OpenAsync(FileAccessMode.Read); BitmapImage image = new BitmapImage(); await image.SetSourceAsync(stream); imgDisplayer.Source = image; NBPlayerState.CurrentImage = targetMedias[0] as NBImage; NBPlayerState.CurrentSourceIndex = 0; NBPlayerState.CurrentPosition = new TimeSpan(0); NBPlayerState.CurrentPlaylist = null; imgDisplayerFrame.Visibility = Visibility.Visible; } lblMediaTitle.Text = targetMedias[(int)NBPlayerState.CurrentSourceIndex].Name; }
public virtual async Task <StorageStreamTransaction> GetTransactionStreamFromFileAsync() { if (StorageItem is StorageFile File) { return(await File.OpenTransactedWriteAsync()); } else { return(await FileRandomAccessStream.OpenTransactedWriteAsync(Path)); } }
public static async Task <BitmapSource> GetImageSource(string name, StorageFolder[] supplementaryFolders = null) { var img = new BitmapImage(); StorageFile imgFile = await GetImageFileFromEverywhereOrDefault(name, supplementaryFolders); FileRandomAccessStream stream = (FileRandomAccessStream)(await imgFile.OpenAsync(FileAccessMode.Read)); img.SetSource(stream); return(img); }
internal SqoWinRTFile(String filePath, bool readOnly) { this.folderPath = filePath.Remove(filePath.LastIndexOf('\\')); this.fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1); isClosed = false; storageFolder = StorageFolder.GetFolderFromPathAsync(folderPath).AsTask().Result; this.file = storageFolder.CreateFileAsync(this.fileName, CreationCollisionOption.OpenIfExists).AsTask().Result; this.fileStream = (FileRandomAccessStream)file.OpenAsync(FileAccessMode.ReadWrite).AsTask().Result; this.stream = fileStream.AsStream(); //this.streamReader = fileStream.AsStreamForRead(); }
/// <summary> /// Load back where we are and the current source to continue from there. /// </summary> private async void loadPlayerState() { // Check if each stored setting is available (not null) and change the media player element based on that. if (NBPlayerState.CurrentPlaylist != null) { if (NBPlayerState.CurrentSourceIndex != null) { if (NBRegistry.GetMedias().Contains(NBPlayerState.CurrentMediaList[(int)NBPlayerState.CurrentSourceIndex])) { NBPlayerState.CurrentPlaylist.MoveTo((uint)NBPlayerState.CurrentSourceIndex); string mediaName = NBPlayerState.CurrentMediaList[(int)NBPlayerState.CurrentSourceIndex].Name; lblMediaTitle.Text = mediaName; } else { NBPlayerState.CurrentPlaylist.Items.RemoveAt((int)NBPlayerState.CurrentSourceIndex); if (NBPlayerState.CurrentSourceIndex + 1 < NBPlayerState.CurrentPlaylist.Items.Count) { NBPlayerState.CurrentPlaylist.MoveTo((uint)NBPlayerState.CurrentSourceIndex + 1); } else if (NBPlayerState.CurrentSourceIndex - 1 >= 0) { NBPlayerState.CurrentPlaylist.MoveTo((uint)NBPlayerState.CurrentSourceIndex - 1); } else { currentMediaPlayer.Source = null; lblMediaTitle.Text = "Nope. No media here yet..."; } } } if (NBPlayerState.CurrentPosition != null) { currentMediaPlayer.PlaybackSession.Position = NBPlayerState.CurrentPosition; } } else if (NBPlayerState.CurrentImage != null) { medPlayer.Visibility = Visibility.Collapsed; FileRandomAccessStream stream = (FileRandomAccessStream)await NBPlayerState.CurrentImage.MediaFile.OpenAsync(FileAccessMode.Read); BitmapImage image = new BitmapImage(); await image.SetSourceAsync(stream); imgDisplayer.Source = image; imgDisplayerFrame.Visibility = Visibility.Visible; } }
public void Close() { if (!isClosed) { isClosed = true; stream.Dispose(); stream = null; fileStream.Dispose(); fileStream = null; this.isModified = false; } }
public async void OnPhotoToFile(StorageFile file) { BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); var result = new Dictionary <string, object> { }; result.Add("Image result", bitmapImage); (Window.Current.Content as Frame).Navigate(typeof(ResultsPage), result); }
// Passing parameter to a new page found at http://stackoverflow.com/questions/35304615/pass-some-parameters-between-pages-in-uwp protected override async void OnNavigatedTo(NavigationEventArgs e) { // Get the image passed in as a parameter base.OnNavigatedTo(e); _photo = (StorageFile)e.Parameter; BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await _photo.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); // Set the image source imgPhoto.Source = bitmapImage; }