private async void AddAppBarButton_Click(object sender, RoutedEventArgs e) { var camera = new CameraCaptureUI(); StorageFile file = await camera.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo); 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); image.Source = bitmapImage; this.DataContext = file; // Add picked file to MostRecentlyUsedList. } else { MessageDialog msgbox = new MessageDialog("Файл не выбран", "Внимание"); await msgbox.ShowAsync(); } }
public async Task GetProjectLogo() { // Arrange ProjectsService svc = new ProjectsService(await GetAuthenticationService()); // Act var projects = await svc.GetProjects(); if (projects?.Count() > 0) { var first = projects.First(); int width = 100, height = 100; var stream = await svc.GetProjectLogo(first.Id, width, height); // Create a .NET memory stream. var memStream = new MemoryStream(); // Convert the stream to the memory stream, because a memory stream supports seeking. await stream.CopyToAsync(memStream); // Set the start position. memStream.Position = 0; // UI Thread needed await ExecuteOnUIThreadAsync(() => { // Create a new bitmap image. var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); // Set the bitmap source to the stream, which is converted to a IRandomAccessStream. bitmap.SetSource(memStream.AsRandomAccessStream()); }); } // Assert // TODO }
private async void OpenAppBarButton_Click(object sender, RoutedEventArgs e) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".mp4"); var 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); image.Source = bitmapImage; this.DataContext = file; // Add picked file to MostRecentlyUsedList. } else { MessageDialog msgbox = new MessageDialog("Файл не выбран", "Внимание"); await msgbox.ShowAsync(); } }
private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1) { /* * Open camera and capture photos * Source: http://windowsapptutorials.com/windows-phone-8-1/media-windows-phone-8-1/using-fileopenpicker-in-windows-phone-8-1-to-choose-picture-from-picture-gallery/ * */ FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs; if (args != null) { if (args.Files.Count == 0) { return; } view.Activated -= viewActivated; storageFile = args.Files[0]; var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await bitmapImage.SetSourceAsync(stream); var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream); img.Source = bitmapImage; } }
void PerformImageVerification(RatingControl rc, String expectedUri, TextBlock resultTb, String stackPanelName, SolidColorBrush expectedColor = null) { ContentPresenter presenter = FindVisualChildByName(rc, "ForegroundContentPresenter") as ContentPresenter; DependencyObject obj = FindVisualChildByName(rc, stackPanelName); var child = VisualTreeHelper.GetChild(obj, 0); Image image = child as Image; var source = image.Source; Windows.UI.Xaml.Media.Imaging.BitmapImage bitImage = source as Windows.UI.Xaml.Media.Imaging.BitmapImage; String uri = bitImage.UriSource.ToString(); if (uri.Equals(expectedUri)) { resultTb.Text = "+"; // Verify colour to make sure we don't accidentally take the non-pointer over as a false-positive // The colours aren't used, but the state is there so we can still check. if (expectedColor == null || presenter.Foreground.Equals(expectedColor)) { resultTb.Text = "+"; } else { resultTb.Text = "/"; } } else { resultTb.Text = "-"; } }
private void Button1_Click(object sender, RoutedEventArgs e) { MessageBlock.Text = "Hello World. We're done presenting."; ImageSource imagesource = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("http://s2.quickmeme.com/img/91/91dd85156980eb1e4de4c8a830faf1b6a3943afcdb5ce77b831c6388eeb6b98a.jpg")); MemeBlock.Source = imagesource; }
public static async Task <Windows.UI.Xaml.Media.Imaging.BitmapImage> GetImageSourceAsync(string ID) { var result = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); var file = (await GetImageFileAsync(ID)); if (file == null) { return(null); } var src = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); if (src == null) { return(null); } try { await result.SetSourceAsync(src); return(result); } catch { return(null); } }
/// <summary> /// Sets the given <paramref name="pic"/> with another picture. /// </summary> /// <param name="pic"><see cref="Windows.UI.Xaml.Controls.PersonPicture"/> to be changed</param> /// <returns>bool? result of the job done.</returns> public static async System.Threading.Tasks.Task <bool?> SetPictureAsync(Windows.UI.Xaml.Controls.PersonPicture pic) { var picker = new Windows.Storage.Pickers.FileOpenPicker { ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail, SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary }; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); var file = await picker.PickSingleFileAsync(); if (file != null) { var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); var image = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); image.SetSource(stream); pic.ProfilePicture = image; return(true); //picture changed successfully } else { return(null); //the file is null } }
private async void GetPhotoButton_Click(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; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); object[] obj = e.Parameter as object[]; site = obj[0] as WebSite; siteName = site.Name; Music music = obj[1] as Music; if (!string.IsNullOrEmpty(siteName) && music != null) { if (site.IsSearcher == null) { string createUrl = string.Format(Constants.DownloadLinkAddress, siteName.ToLower(), music.Url); webGard.Begin(createUrl); if (!string.IsNullOrEmpty(music.ImageUrl)) { var image = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(music.ImageUrl)); img.Source = image; } } else { LV.Items.Add("Searcher site has download link."); LV.Items.Add("No need to get them!"); } } }
private async void Button_Click_1(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; } }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState) { if (pageState != null && pageState.ContainsKey("mruToken")) { object value = null; if (pageState.TryGetValue("mruToken", out value)) { if (value != null) { mruToken = value.ToString(); // Open the file via the token that you stored when adding this file into the MRU list. Windows.Storage.StorageFile file = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken); 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 a bitmap. Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmapImage.SetSource(fileStream); displayImage.Source = bitmapImage; // Set the data context for the page. this.DataContext = file; } } } } }
public MainPage() { this.InitializeComponent(); this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += navigationHelper_LoadState; this.navigationHelper.SaveState += navigationHelper_SaveState; //Resource var resource = new Windows.ApplicationModel.Resources.ResourceLoader(); var title = resource.GetString("Message"); pageTitle.Text = title; var heading = resource.GetString("Heading"); tbHeading.Text = heading; var text = resource.GetString("Text"); tbText.Text = text; var buttonLabel = resource.GetString("Button"); btnOk.Content = buttonLabel; var imgName = resource.GetString("Image"); Windows.UI.Xaml.Media.Imaging.BitmapImage bitImg = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitImg.UriSource = new Uri(this.BaseUri, "Assets/" + imgName); imgFlag.Source = bitImg; }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState) { if (pageState != null && pageState.ContainsKey("mruToken")) { object value = null; if (pageState.TryGetValue("mruToken", out value)) { if (value != null) { mruToken = value.ToString(); //reopen the file with the stored token. Windows.Storage.StorageFile file = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken); if (file != null) { Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmapImage.SetSource(fileStream); displayImage.Source = bitmapImage; this.DataContext = file; } } } } }
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { var folderPicker = new Windows.Storage.Pickers.FolderPicker(); folderPicker.FileTypeFilter.Add(".jpg"); var folder = await folderPicker.PickSingleFolderAsync(); var filesList = await folder.CreateFileQueryWithOptions(new QueryOptions(CommonFileQuery.DefaultQuery, new string[] { ".jpg" })).GetFilesAsync(); for (int i = 0; i < filesList.Count; i++) { using (var stream = await filesList[i].OpenAsync(Windows.Storage.FileAccessMode.Read)) { Debug.WriteLine(filesList[i].Name); var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await bitmapImage.SetSourceAsync(stream); Image m = new Image(); m.Source = bitmapImage; Stack.Children.Add(m); } } }
private async System.Threading.Tasks.Task <bool> SetDefaultPicture() { var uri = new System.Uri("ms-appx:///Assets/Photo.png"); Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri); if (file != null) { using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { if (fileStream != null) { Windows.UI.Xaml.Media.Imaging.BitmapImage b = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); if (b != null) { b.SetSource(fileStream); SetPictureSource(b); SetPictureElementSize(); return(true); } } } } return(false); }
private async void image_Click(object sender, RoutedEventArgs e) { var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); var file = await openPicker.PickSingleFileAsync(); if (file == null) { return; } using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmap.SetSource(stream); Image1.Source = bitmap; } }
public ProductItem(Product product) { Label = string.Format(" {0} | {1} | {2:C} ", product.ToString(), product.Category.ToString(), product.Cost.ToString()); #if WINDOWS_UWP || WPF ImageSource = new Image(); #endif #if WINDOWS_UWP LoadImageAsync(product); #elif XF ImageSource = ImageSource.FromStream(() => new MemoryStream(product.Image)); #else using (var stream = new MemoryStream(product.Image)) { #if WPF ImageSource.BeginInit(); ImageSource.CacheOption = BitmapCacheOption.OnLoad; ImageSource.StreamSource = stream; ImageSource.EndInit(); #else ImageSource = Image.FromStream(stream); #endif } #endif }
private void btnLoad_Click(object sender, RoutedEventArgs e) { var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/GTS300i.png")); ImgDemo.Stretch = Stretch.Uniform; ImgDemo.Source = bitmapImage; }
private void EditedRouteExistingWayPointsBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { Waypoint waypoint = ExistingWayPointsBox2.SelectedItem as Waypoint; if (waypoint is PointOfInterest) { PointOfInterest poi = waypoint as PointOfInterest; Windows.UI.Xaml.Media.Imaging.BitmapImage icon = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); try { icon.UriSource = new Uri(poi.ImagePath); ImageExistingWayPoint2.Source = icon; } catch { } LatitudeExistingWayPoint2.Text = poi.Latitude.ToString(); LongitudeExistingWayPoint2.Text = poi.Longitude.ToString(); NameExistingWayPoint2.Text = poi.Name; Text2.Text = poi.Information; ImagePathExistingWayPoint2.Text = poi.ImagePath.ToString(); } else { ImageExistingWayPoint2.Source = null; LatitudeExistingWayPoint2.Text = waypoint.Latitude.ToString(); LongitudeExistingWayPoint2.Text = waypoint.Longitude.ToString(); NameExistingWayPoint2.Text = ""; ImagePathExistingWayPoint2.Text = ""; } }
public static async Task LoadPictureAsync(FrameworkElement sender) { try { if (sender.Parent is Panel pl) { if (pl.FindName("pro") is TextBlock ring) { ring.Visibility = Visibility.Visible; try { var img = sender as Image; if (img.DataContext != null) { var work = (img.DataContext as Work); using (var stream = await Data.TmpData.CurrentAuth.Tokens.SendRequestToGetImageAsync(Pixeez.MethodType.GET, work.ImageUrls.Medium)) { var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await bitmap.SetSourceAsync((await stream.GetResponseStreamAsync()).AsRandomAccessStream()); img.Source = bitmap; } } } finally { ring.Visibility = Visibility.Collapsed; } } } } catch { } }
private async void GetPhoto_Click(object sender, RoutedEventArgs e) { //File picker APIs don't work if the app is in a snapped state. //Try to unsnap the app first. only launch the picker if it unsnapped if (Windows.UI.ViewManagement.ApplicationView.Value != Windows.UI.ViewManagement.ApplicationViewState.Snapped || Windows.UI.ViewManagement.ApplicationView.TryUnsnap() == true) { Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; openPicker.FileTypeFilter.Clear(); openPicker.FileTypeFilter.Add(".bmp"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmapImage.SetSource(fileStream); displayImage.Source = bitmapImage; this.DataContext = file; mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file); } } }
public async Task SetImageAsync(Windows.Storage.Streams.IRandomAccessStream imageStream) { var bmp = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await bmp.SetSourceAsync(imageStream); this.canvasImage.Source = bmp; }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { if (pageState != null && pageState.ContainsKey("mruToken")) { object value = null; if (pageState.TryGetValue("mruToken", out value)) { if (value != null) { mruToken = value.ToString(); // Open the file via the token that you stored when adding this file into the MRU list. Windows.Storage.StorageFile file = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken); 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 a bitmap. Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmapImage.SetSource(fileStream); displayImage.Source = bitmapImage; // Set the data context for the page. this.DataContext = file; } } } } }
/// <summary> /// 将获取到的流转成bitmap /// </summary> /// <param name="file"></param> /// <returns></returns> public Windows.UI.Xaml.Media.Imaging.BitmapImage ConverToBitmapImage(IRandomAccessStream stream) { var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmap.SetSource(stream); return(bitmap); }
public LiveId(IDictionary<string, object> result, Uri image) { Id = result.ContainsKey("id") ? result["id"] as string : string.Empty; NameFull = result.ContainsKey("name") ? result["name"] as string : string.Empty; NameFirst = result.ContainsKey("first_name") ? result["first_name"] as string : string.Empty; NameLast = result.ContainsKey("last_name") ? result["last_name"] as string : string.Empty; Gender = result.ContainsKey("gender") ? result["gender"] as string : string.Empty; Locale = result.ContainsKey("locale") ? result["locale"] as string : string.Empty; Uri _Uri; if (Uri.TryCreate(result.ContainsKey("link") ? result["link"] as string : string.Empty, UriKind.Absolute, out _Uri)) Link = _Uri; DateTime _Date; if (DateTime.TryParse(result.ContainsKey("updated_time") ? result["updated_time"] as string : string.Empty, out _Date)) UpdatedTime = _Date; var _Emails = result.ContainsKey("emails") ? result["emails"] as IDictionary<string, object> : new Dictionary<string, object>(); EmailPreferred = _Emails.ContainsKey("preferred") ? _Emails["preferred"] as string : string.Empty; EmailAccount = _Emails.ContainsKey("account") ? _Emails["account"] as string : string.Empty; if (image != null) { PhotoLocation = image; var _PhotoBitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(image); PhotoBitmap = _PhotoBitmap; } }
private async void SelectPictureButton_Click(object sender, RoutedEventArgs e) { Windows.Storage.Pickers.FileOpenPicker filePicker = new Windows.Storage.Pickers.FileOpenPicker(); filePicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; filePicker.FileTypeFilter.Add(".jpg"); filePicker.FileTypeFilter.Add(".jpeg"); filePicker.FileTypeFilter.Add(".png"); filePicker.FileTypeFilter.Add(".bmp"); filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; StorageFile file = await filePicker.PickSingleFileAsync(); if (file != null) { 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); Image.Source = bitmapImage; ImageName = file.Name; ImagePath = file.Path; Windows.Storage.StorageFolder targetFolder = await StorageFolder.GetFolderFromPathAsync(Models.TodoItem.ImagePath); await file.CopyAsync(targetFolder, ImageName, NameCollisionOption.ReplaceExisting); } } }
public object Convert(object value, Type targetType, object parameter, string language) { var result = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); ThumbnailManager.SetToImageSourceNoWait(value.ToString(), result); return(result); }
private void UnloginOnCommandAct(IUICommand command) { if ((int)(command.Id) == 1) { Class.UserManager.unLogin(); } if (Class.UserManager.isLogin()) { var ellipse = new Ellipse(); ellipse.Width = 45; ellipse.Height = 45; ellipse.Margin = new Thickness(-10); var imgsource = new Windows.UI.Xaml.Media.Imaging.BitmapImage() { UriSource = new Uri(Class.UserManager.GetData(Class.UserManager.Type.pic)) }; ellipse.Fill = new ImageBrush() { ImageSource = imgsource }; UserLoginBtn.Content = ellipse; } else { UserLoginBtn.Content = new SymbolIcon(Symbol.Contact2); } }
public Func <ImageSource> GetIconLarge(IFileItem item) { if (item?.IsFolder == true) { return(() => IconLargeCache = IconLargeCache ?? new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///FileExplorerControl/res/Icons/folder_l.png"))); } return(null); }
/// <summary> /// Thank you StackOverFlow! Uses relative URI string to get the BitmapImage from file. /// </summary> /// <param name="parent">FrameworkElement assotiated with image</param> /// <param name="path">String representing relative URI</param> public static Windows.UI.Xaml.Media.Imaging.BitmapImage ImageFromRelativePath(FrameworkElement parent, string path) { var uri = new Uri(parent.BaseUri, path); Windows.UI.Xaml.Media.Imaging.BitmapImage result = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); result.UriSource = uri; return(result); }
private void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e) { //If the image failed to load, go back to a lower resolution (usually the first) Image ima = sender as Image; Windows.UI.Xaml.Media.Imaging.BitmapImage bmp = ima.DataContext as Windows.UI.Xaml.Media.Imaging.BitmapImage; bmp.UriSource = new Uri(bmp.UriSource.ToString().Replace("357x500", "30x42")); }
public Windows.UI.Xaml.Media.Imaging.BitmapImage GetBitmapSource(System.IO.Stream stream) { Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); Windows.Storage.Streams.InMemoryRandomAccessStream ras = new Windows.Storage.Streams.InMemoryRandomAccessStream(); stream.CopyTo(System.IO.WindowsRuntimeStreamExtensions.AsStreamForRead(ras)); bitmapSource.SetSource(ras); return bitmapSource; }
private async void init() { LoadProgress.IsActive = true; var appfolder = ApplicationData.Current.LocalFolder; var localSettings = ApplicationData.Current.LocalSettings; if (!localSettings.Values.ContainsKey("isfirst")) { localSettings.Values["StartVoice"] = false; localSettings.Values["StartVoiceId"] = 0; var datafolder = await appfolder.CreateFolderAsync("Data", CreationCollisionOption.ReplaceExisting); await appfolder.CreateFolderAsync("Temp", CreationCollisionOption.ReplaceExisting); await datafolder.CreateFileAsync("localfolders.json", CreationCollisionOption.ReplaceExisting); await datafolder.CreateFileAsync("locallist.json", CreationCollisionOption.ReplaceExisting); await datafolder.CreateFileAsync("nowplay.json", CreationCollisionOption.ReplaceExisting); await datafolder.CreateFileAsync("nowplay.lrc", CreationCollisionOption.ReplaceExisting); await datafolder.CreateFileAsync("playlist.json", CreationCollisionOption.ReplaceExisting); localSettings.Values["isfirst"] = true; if (ResourceLoader.GetForCurrentView().GetString("OKBtn") != "OK") { await new MessageDialog("如果觉得好用请给我点支持,支付宝:[email protected],**斌,交流群:192101837", "捐赠(下次不再显示)").ShowAsync(); } } if (Class.UserManager.isLogin()) { var ellipse = new Ellipse(); ellipse.Width = 45; ellipse.Height = 45; ellipse.Margin = new Thickness(-10); var imgsource = new Windows.UI.Xaml.Media.Imaging.BitmapImage() { UriSource = new Uri(Class.UserManager.GetData(Class.UserManager.Type.pic)) }; ellipse.Fill = new ImageBrush() { ImageSource = imgsource }; UserLoginBtn.Content = ellipse; } else { UserLoginBtn.Content = new SymbolIcon(Symbol.Contact2); } //await Class.Model.PlayList.Clear(); KanPagePanel.LoadData(); await init_local_list(); CheckFeedBack(); LoadProgress.IsActive = false; }
public static async Task<Windows.UI.Xaml.Media.Imaging.BitmapImage> GetImageSourceAsync(string ID) { var result= new Windows.UI.Xaml.Media.Imaging.BitmapImage(); var file = (await GetImageFileAsync(ID)); if (file == null) return null; var src = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); if (src == null) return null; try { await result.SetSourceAsync(src); return result; } catch { return null; } }
private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1) { FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs; if (args != null) { if (args.Files.Count == 0) return; view.Activated -= viewActivated; StorageFile storageFile = args.Files[0]; var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await bitmapImage.SetSourceAsync(stream); var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream); img.Source=bitmapImage; } }
/// <summary> /// このページには、移動中に渡されるコンテンツを設定します。前のセッションからページを /// 再作成する場合は、保存状態も指定されます。 /// </summary> /// <param name="sender"> /// イベントのソース (通常、<see cref="NavigationHelper"/>)> /// </param> /// <param name="e">このページが最初に要求されたときに /// <see cref="Frame.Navigate(Type, Object)"/> に渡されたナビゲーション パラメーターと、 /// 前のセッションでこのページによって保存された状態の辞書を提供する /// セッション。ページに初めてアクセスするとき、状態は null になります。</param> private async void navigationHelper_LoadState (object sender, LoadStateEventArgs e) { if (e.PageState != null && e.PageState.ContainsKey ("mruToken")) { object value = null; if (e.PageState.TryGetValue ("mruToken", out value)) { if (value != null) { mruToken = value.ToString (); var file = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync (mruToken); if (file != null) { var fileStream = await file.OpenAsync (Windows.Storage.FileAccessMode.Read); var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage (); bitmapImage.SetSource (fileStream); displayImage.Source = bitmapImage; DataContext = file; } } } } }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { if (pageState != null && pageState.ContainsKey("mruToken")) { object value = null; if (pageState.TryGetValue("mruToken", out value)) { if (value != null) { mruToken = value.ToString(); //reopen the file with the stored token. Windows.Storage.StorageFile file = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken); if (file != null) { Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmapImage.SetSource(fileStream); displayImage.Source = bitmapImage; this.DataContext = file; } } } } }
// Reset all fields to empty box private void ResetFields() { titleTextBox.Text = ""; locationTextBox.Text = ""; startDatePicker.Date = System.DateTime.Now; endDatePicker.Date = System.DateTime.Now; descTextBox.Text = ""; categoryComboBox.SelectedIndex = 0; feeTextBox.Text = ""; image = null; // Set back image preview slot to no image Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx://Evenue.ClientApp/Assets/noimage.jpg")); imagePreview.Source = bitmapImage; ValidationErrorText.Visibility = Visibility.Collapsed; }
/// <summary> /// Thank you StackOverFlow! Uses relative URI string to get the BitmapImage from file. /// </summary> /// <param name="parent">FrameworkElement assotiated with image</param> /// <param name="path">String representing relative URI</param> public static Windows.UI.Xaml.Media.Imaging.BitmapImage ImageFromRelativePath(FrameworkElement parent, string path) { var uri = new Uri(parent.BaseUri, path); Windows.UI.Xaml.Media.Imaging.BitmapImage result = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); result.UriSource = uri; return result; }
private void InitBackground() { if (App.MainPageBackgroundImageStream != null) { var backgroundImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); backgroundImage.SetSource(App.MainPageBackgroundImageStream); backgoundBrush.ImageSource = backgroundImage; } else { Uri imageUri = new Uri(CareConstDefine.MainPageBackgroundURI); var backgroundImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(imageUri); backgoundBrush.ImageSource = backgroundImage; } }
private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1) { FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs; if (args != null) { if (args.Files.Count == 0) return; view.Activated -= viewActivated; StorageFile storageFile = args.Files[0]; var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await bitmapImage.SetSourceAsync(stream); var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream); img.Source = bitmapImage; //PictureTags.Text = storageFile.Name; //PassPictureData.picture_view_source2 = storageFile.Name; var obj = App.Current as App; obj.exam2 = storageFile.Name; //getting data from DB ReadClothesList db_clothes = new ReadClothesList(); SeasonTxtBlck.Text = db_clothes.GetSeasonData(); CategoryTxtBlck.Text = db_clothes.GetCategoryData(); KindTxtBlck.Text = db_clothes.GetKindData(); } }
public object Convert(object value, Type targetType, object parameter, string language) { var result = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); ThumbnailManager.SetToImageSourceNoWait(value.ToString(), result); return result; }
/// <summary> /// This method set the poster source for the MediaElement /// </summary> private async System.Threading.Tasks.Task<bool> SetPosterUrl(string PosterUrl) { if (IsPicture(PosterUrl)) { if (IsLocalFile(PosterUrl)) { try { Windows.Storage.StorageFile file = await GetFileFromLocalPathUrl(PosterUrl); if (file != null) { using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { if (fileStream != null) { Windows.UI.Xaml.Media.Imaging.BitmapImage b = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); if (b != null) { b.SetSource(fileStream); SetPictureSource(b); SetPictureElementSize(); return true; } } } } else LogMessage("Failed to load poster: " + PosterUrl); } catch (Exception e) { LogMessage("Exception while loading poster: " + PosterUrl + " - " + e.Message); } } else { try { // Load the bitmap image over http Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient(); Windows.Storage.Streams.InMemoryRandomAccessStream ras = new Windows.Storage.Streams.InMemoryRandomAccessStream(); using (var stream = await httpClient.GetInputStreamAsync(new Uri(PosterUrl))) { if (stream != null) { await stream.AsStreamForRead().CopyToAsync(ras.AsStreamForWrite()); ras.Seek(0); var b = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); if (b != null) { await b.SetSourceAsync(ras); SetPictureSource(b); SetPictureElementSize(); return true; } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception: " + e.Message); } } } return false; }
private async void GetPhotoButton_Click (object sender, RoutedEventArgs e) { var openPicker = new Windows.Storage.Pickers.FileOpenPicker (); openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; openPicker.FileTypeFilter.Clear (); openPicker.FileTypeFilter.Add (".bmp"); openPicker.FileTypeFilter.Add (".png"); openPicker.FileTypeFilter.Add (".jpeg"); openPicker.FileTypeFilter.Add (".jpg"); var file = await openPicker.PickSingleFileAsync (); if (file != null) { var fileStream = await file.OpenAsync (Windows.Storage.FileAccessMode.Read); var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage (); bitmapImage.SetSource (fileStream); displayImage.Source = bitmapImage; DataContext = file; } mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add (file); }
private async void GetPhotoButton_Click(object sender, RoutedEventArgs e) { // File picker APIs don't work if the app is in a snapped state. // If the app is snapped, try to unsnap it first. Only show the picker if it unsnaps. if (Windows.UI.ViewManagement.ApplicationView.Value != Windows.UI.ViewManagement.ApplicationViewState.Snapped || Windows.UI.ViewManagement.ApplicationView.TryUnsnap() == true) { 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; // Add picked file to MostRecentlyUsedList and get a token. mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file); } } }
public static void Unload() { Stop(); //if (_state.IsSharpDxRendering) //{ // if (BackgroundSIS != null) // { // BackgroundSIS.Unload(); // BackgroundSIS = null; // } // if (MagicSIS != null) // { // MagicSIS.Unload(); // MagicSIS = null; // } // if (_renderer1 != null) // { // _renderer1.Unload(); // _renderer1 = null; // } // if (_renderer2 != null) // { // _renderer2.Unload(); // _renderer2 = null; // } // if (_deviceManager1 != null) // { // _deviceManager1.Dispose(); // _deviceManager1 = null; // } // if (_deviceManager2 != null) // { // _deviceManager2.Dispose(); // _deviceManager2 = null; // } //} //else //{ //FALLBACK TO IMAGE/WRITEABLEBITMAP RENDERING BackgroundImage.Source = null; BackgroundImage = null; BackgroundBitmapImage = null; ExplosionSurface = null; //} IsInitialized = false; //need to do the disposing of the dx surfaces and pipeline here! }
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args) { try { Util.debugLog("Hello"); if (args.Files.Count > 0) { Util.debugLog("Hello"); textAddImage.Label = "Replace Image"; var stream = await args.Files[0].OpenAsync(Windows.Storage.FileAccessMode.Read); var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await bitmapImage.SetSourceAsync(stream); CameraPreview.Source = bitmapImage; RandomAccessStreamReference rasr = RandomAccessStreamReference.CreateFromStream(stream); var streamWithContent = await rasr.OpenReadAsync(); byte[] buffer = new byte[streamWithContent.Size]; //showProcessRing(); await streamWithContent.ReadAsync(buffer.AsBuffer(), (uint)streamWithContent.Size, InputStreamOptions.None); //hideProcessRing(); str = Convert.ToBase64String(buffer); int S1Length = str.Length; Util.debugLog(str); } } catch { Util.debugLog("s2"); } }
// Open the image picker private async void BrowseImage(object sender, RoutedEventArgs e) { FileOpenPicker picker = new FileOpenPicker(); picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; picker.ViewMode = PickerViewMode.Thumbnail; // Set the file extensions picker.FileTypeFilter.Clear(); picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".bmp"); picker.FileTypeFilter.Add(".png"); image = await picker.PickSingleFileAsync(); if (image != null) { // Open a stream for the selected file. Windows.Storage.Streams.IRandomAccessStream fileStream = await image.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); imagePreview.Source = bitmapImage; } }
public static void Init(GlobalState state) { _state = state; //if (state != null && state.IsSharpDxRendering) //{ // BaseRenderer.UpdateState((BaseRenderer)BackgroundRenderer, state); // BaseRenderer.UpdateState((BaseRenderer)MagicRenderer, state); //} if (IsInitialized) return; //if (state.IsSharpDxRendering) //{ // _deviceManager1 = new CommonDX.DeviceManager(); // _deviceManager2 = new CommonDX.DeviceManager(); // _renderer1 = new DxRenderer.BackgroundComposer() { State = _state }; // _renderer2 = new DxRenderer.MagicComposer() { State = _state }; // BackgroundSIS = new SumoNinjaMonkey.Framework.Controls.DrawingSurfaceSIS( // (gt) => { _renderer1.Update(gt); }, // (tb) => { _renderer1.Render(tb); }, // (dm) => { _renderer1.Initialize(dm); }, // (e1, e2) => { _renderer1.InitializeUI(e1, e2); }, // (uri) => { _renderer1.LoadLocalAsset(uri); }, // () => { _renderer1.Unload(); }, // _deviceManager1); // //_renderer1, _deviceManager1); // MagicSIS = new SumoNinjaMonkey.Framework.Controls.DrawingSurfaceSIS( // (gt) => { _renderer2.Update(gt); }, // (tb) => { _renderer2.Render(tb); }, // (dm) => { _renderer2.Initialize(dm); }, // (e1, e2) => { _renderer2.InitializeUI(e1, e2); }, // (uri) => { _renderer2.LoadLocalAsset(uri); }, // () => { _renderer2.Unload(); }, // _deviceManager2); // //_renderer2, _deviceManager2); //} //else //{ //FALLBACK TO IMAGE/WRITEABLEBITMAP RENDERING BackgroundBitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); BackgroundBitmapImage.UriSource = new Uri(_state.DefaultBackgroundUri); BackgroundImage = new Windows.UI.Xaml.Controls.Image(); BackgroundImage.Source = BackgroundBitmapImage; BackgroundImage.Stretch = Windows.UI.Xaml.Media.Stretch.UniformToFill; BackgroundImage.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch; BackgroundImage.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch; //FALLBACK TO XAML EXPLOSIONS ExplosionSurface = new SumoNinjaMonkey.Framework.Controls.Explosions.DrawingSurface(); ExplosionSurface.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch; ExplosionSurface.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch; //} IsInitialized = true; }
private async void viewActivated(CoreApplicationView sender, Windows.ApplicationModel.Activation.IActivatedEventArgs args1) { FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs; if (args != null) { if (args.Files.Count == 0) return; view.Activated -= viewActivated; StorageFile storageFile = args.Files[0]; fileBytes = null; var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await bitmapImage.SetSourceAsync(stream); fileBytes = new byte[stream.Size]; await stream.ReadAsync(fileBytes.AsBuffer(), (uint)stream.Size, Windows.Storage.Streams.InputStreamOptions.None); var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream); imageDp.Source = bitmapImage; imageDp.Height = CoreApplication.GetCurrentView().CoreWindow.Bounds.Height; imageDp.Width = CoreApplication.GetCurrentView().CoreWindow.Bounds.Width; buttonAddImage.Content = "change image"; } }
public async Task LoadImageAsync() { StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(ImagePath); StorageFile file = await folder.GetFileAsync(ImageName); using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(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); _image = bitmapImage; } }