// Sample code for building a localized ApplicationBar //private void BuildLocalizedApplicationBar() //{ // // Set the page's ApplicationBar to a new instance of ApplicationBar. // ApplicationBar = new ApplicationBar(); // // Create a new button and set the text value to the localized string from AppResources. // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); // appBarButton.Text = AppResources.AppBarButtonText; // ApplicationBar.Buttons.Add(appBarButton); // // Create a new menu item with the localized string from AppResources. // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); // ApplicationBar.MenuItems.Add(appBarMenuItem); //} protected override void OnNavigatedTo(NavigationEventArgs e) { if (State.ContainsKey("customCamera")) { State.Remove("customCamera"); InitializeCamera(); } IDictionary <string, string> queryStrings = NavigationContext.QueryString; string action = null; if (queryStrings.ContainsKey("Action")) { action = queryStrings["Action"]; } string token = null; if (queryStrings.ContainsKey("FileId")) { token = queryStrings["FileId"]; } if (!string.IsNullOrEmpty(token)) { MediaLibrary mediaLib = new MediaLibrary(); Picture picture = mediaLib.GetPictureFromToken(token); currentImage = PictureDecoder.DecodeJpeg(picture.GetImage()); photoContainer.Fill = new ImageBrush { ImageSource = currentImage }; imageDetails.Text = string.Format("Image from {0} action.\nPicture name:\n{1}\nMedia library token:\n{2}", action, picture.GetPath(), token); } }
/// <summary> /// Handles when the app is navigated to from: /// o rightclick > apps... > *APPNAME* /// o rickclick > Edit > *APPNAME* /// o Launched from lenses /// </summary> /// <param name="e"></param> protected override void OnNavigatedTo(NavigationEventArgs e) { // Get a dictionary of query string keys and values. IDictionary <string, string> queryStrings = this.NavigationContext.QueryString; // Ensure that there is at least one key in the query string, and check whether the "token" key is present. if (queryStrings.ContainsKey("token")) { //launched from apps... MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(queryStrings["token"]); // Renderer.LoadNewImage(toScreen, PictureDecoder.DecodeJpeg(picture.GetImage())); } else if (queryStrings.ContainsKey("FileId")) { //launched from Edit MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(queryStrings["FileId"]); // Renderer.LoadNewImage(toScreen, PictureDecoder.DecodeJpeg(picture.GetImage())); } else { //launched from lens if (App.LaunchedFromLens) { newImg_click(null, new EventArgs()); App.LaunchedFromLens = false; } } }
protected override void OnActivate() { var library = new MediaLibrary(); var photoFromLibrary = library.GetPictureFromToken(FileId); var image = photoFromLibrary.GetImage(); var buffer = LerTudo(image); dadosDaMulta.ExibirImagem(image, true); fileInfo = new HttpUpload.FileInfo { FileName = photoFromLibrary.Name, ContentType = "image/jpeg", Buffer = buffer, ParamName = "multa[foto]" }; dadosDaMulta.PropertyChanged += (sender, e) => { if (e.PropertyName == "IsValid") { NotifyOfPropertyChange("CanShare"); } }; base.OnActivate(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { try { IDictionary <string, string> queryStrings = this.NavigationContext.QueryString; if (queryStrings.ContainsKey("token")) { MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(queryStrings["token"]); BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(picture.GetImage()); WriteableBitmap picLibraryImage = new WriteableBitmap(bitmap); imgPhoto.Source = picLibraryImage; } if (queryStrings.ContainsKey("FileId")) { MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(queryStrings["FileId"]); BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(picture.GetImage()); WriteableBitmap picLibraryImage = new WriteableBitmap(bitmap); imgPhoto.Source = picLibraryImage; } } catch (Exception ex) { Dispatcher.BeginInvoke(() => txtStatus.Text = ex.Message); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { // Get a dictionary of query string keys and values. IDictionary <string, string> queryStrings = this.NavigationContext.QueryString; // Check whether the app has been started by the photo edit picker of the Windows Phone System // More information about the photo edit picker here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202966(v=vs.105).aspx if (queryStrings.ContainsKey("FileId") && imageAlreadyLoaded == false) { imageAlreadyLoaded = true; // Retrieve the photo from the media library using the FileID passed to the app. MediaLibrary library = new MediaLibrary(); Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["FileId"]); // Create a BitmapImage object and add set it as the PreviewImage BitmapImage bitmapFromPhoto = new BitmapImage(); bitmapFromPhoto.SetSource(photoFromLibrary.GetPreviewImage()); SetPreviewImage(bitmapFromPhoto); } // Every time we navigate to the MainPage we check if a filter has been selected on the FilterView page // If so, we apply this filter to the PreviewImage if (FilterSelectorView.SelectedFilter != null) { await ApplyFilter(FilterSelectorView.SelectedFilter, PreviewPicture); } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnNavigatedTo(NavigationEventArgs e) { // Get a dictionary of query string keys and values. IDictionary <string, string> queryStrings = this.NavigationContext.QueryString; // Ensure that there is at least one key in the query string, and check whether the "token" key is present. if (queryStrings.ContainsKey("token")) { // Retrieve the photo from the media library using the token passed to the app. var library = new MediaLibrary(); var photoFromLibrary = library.GetPictureFromToken(queryStrings["token"]); if (Photos.SaveBackgroundImage(photoFromLibrary.GetImage())) { GoHome(); } else { MessageBox.Show("Sorry, unable to use that photo. Please try another one."); } } if (queryStrings.ContainsKey("goto")) { SettingsPanorama.DefaultItem = SettingsPanorama.Items[Convert.ToInt32(queryStrings["goto"])]; } EnableAnimatedGifSetting.IsChecked = _appSettings.EnableAnimatedGifSetting; BackgroundAgentToggle.IsChecked = _backgroundAgent.IsRunning(); AgentStatus.Text = string.Format("Keeps the live tile content up to date. Last run: {0}", _backgroundAgent.LastRun()); base.OnNavigatedTo(e); }
protected override void OnNavigatedTo(NavigationEventArgs args) { if (this.NavigationContext.QueryString.ContainsKey("token")) { string token = this.NavigationContext.QueryString["token"]; MediaLibrary mediaLib = new MediaLibrary(); Picture picture = mediaLib.GetPictureFromToken(token); Stream stream = picture.GetImage(); jpegBits = new byte[stream.Length]; stream.Read(jpegBits, 0, jpegBits.Length); LoadBitmap(jpegBits); } else if (appService.State.ContainsKey("colorBits")) { int[] colorBits = (int[])appService.State["colorBits"]; bitSelectDialog.Initialize(colorBits); } if (appService.State.ContainsKey("jpegBits")) { jpegBits = (byte[])appService.State["jpegBits"]; LoadBitmap(jpegBits); } base.OnNavigatedTo(args); }
private void createTemporaryImage(string token) { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { string file_name = "image.jpg"; if (store.FileExists(file_name)) { store.DeleteFile(file_name); } using (MediaLibrary library = new MediaLibrary()) { using (Picture picture = library.GetPictureFromToken(token)) { if (picture != null) { using (Stream picture_stream = picture.GetImage()) { WriteableBitmap bitmap = PictureDecoder.DecodeJpeg(picture_stream, MAX_LOADED_WIDTH, MAX_LOADED_HEIGHT); using (IsolatedStorageFileStream stream = store.CreateFile(file_name)) { bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100); } } } } } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); IDictionary <string, string> queryStrings = NavigationContext.QueryString; if (queryStrings.ContainsKey("FileId")) { shareFromLibary = true; ApplicationTitle.Text = "Share a picture"; MediaLibrary library = new MediaLibrary(); string filename = queryStrings["FileId"]; Picture picture = library.GetPictureFromToken(filename); Action upload = () => uploadImage(picture.GetImage()); if (App.Settings.GetValueOrDefault <bool>("Logged", false)) { upload(); } else { App.SignedInCallback += upload; } } else if (queryStrings.ContainsKey("pid")) { appbar.IsVisible = false; App.Progress.IsIndeterminate = true; App.Progress.Text = "Loading..."; App.Progress.IsVisible = true; reshareId = queryStrings["pid"]; new Request("POST", APIs.GetActivity, result => { if (result.Success) { Post orginalPost = new Post(JArray.Parse(result.RawData.Substring(6))[0][1][1], fullInfo: false); if (orginalPost.IsReshare) { orginalPost.AuthorPhoto = orginalPost.OriginalAuthorPhoto; orginalPost.Author = orginalPost.OriginalAuthor; orginalPost.Content = orginalPost.OriginalContent; } DataContext = orginalPost; App.Progress.IsVisible = false; appbarShare.IsEnabled = true; appbarAddPhoto.IsEnabled = false; appbarAddLink.IsEnabled = false; ApplicationBar.IsVisible = true; } else { MessageBox.Show("Please check your network", "Can't reach Google", MessageBoxButton.OK); throw new Exception("ExitAppException"); } }, new GetActivityObject(reshareId).ToString()); } }
public async Task FromToken(string token) { using (var library = new MediaLibrary()) { using (var picture = library.GetPictureFromToken(token)) { await FromLibraryPath(picture.GetPath()); } } }
public void FromLibraryImage(string token) { System.Diagnostics.Debug.Assert(token != null); using (var library = new MediaLibrary()) { using (var picture = library.GetPictureFromToken(token)) { var libraryPath = picture.GetPath(); if (LibraryPath != libraryPath) { LibraryPath = libraryPath; LocalPath = Mapping.MatchLibraryPathWithLocalPath(libraryPath); if (LocalPath != null) { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { Image = store.OpenFile(LocalPath, FileMode.Open); } } else { Image = picture.GetImage(); } OriginalPath = Mapping.MatchPathWithOriginalPath(libraryPath); if (OriginalPath != null) { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { Original = store.OpenFile(OriginalPath, FileMode.Open); } } else { Original = null; } OriginalLibraryPath = null; } } } }
private void SetChoosenPhoto(string fileId) { using (MediaLibrary mediaLibrary = new MediaLibrary()) { using (Picture pictureFromToken = mediaLibrary.GetPictureFromToken(fileId)) { ParametersRepository.SetParameterForId("ChoosenPhotosPreviews", new List <Stream>() { pictureFromToken.GetThumbnail() }); ParametersRepository.SetParameterForId("ChoosenPhotos", new List <Stream>() { pictureFromToken.GetImage() }); } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { // QueryString Date abrufen IDictionary <string, string> queryStrings = NavigationContext.QueryString; if (queryStrings.ContainsKey("Action")) { string fileToken = string.Empty; if (queryStrings.ContainsKey("token")) { fileToken = queryStrings["token"]; } else if (queryStrings.ContainsKey("FileId")) { fileToken = queryStrings["FileId"]; } if (!string.IsNullOrEmpty(fileToken)) { // Gestartet von Bilder-App => Bild laden Picture picture = library.GetPictureFromToken(fileToken); TheImage.Source = GetImage(picture); } // Action als Seitentitel verwenden PageTitle.Text = queryStrings["Action"]; } else { if (State.ContainsKey(fromChooser)) { // Zurückgekehrt von Chooser - nicht erneut anzeigen State.Remove(fromChooser); } else { // App normal gestartet => PhotoChooser öffnen State[fromChooser] = true; photoChooser.Show(); } } }
// Sample code for building a localized ApplicationBar //private void BuildLocalizedApplicationBar() //{ // // Set the page's ApplicationBar to a new instance of ApplicationBar. // ApplicationBar = new ApplicationBar(); // // Create a new button and set the text value to the localized string from AppResources. // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); // appBarButton.Text = AppResources.AppBarButtonText; // ApplicationBar.Buttons.Add(appBarButton); // // Create a new menu item with the localized string from AppResources. // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); // ApplicationBar.MenuItems.Add(appBarMenuItem); //} protected override void OnNavigatedTo(NavigationEventArgs e) { if (State.ContainsKey("customCamera")) { State.Remove("customCamera"); InitializeCamera(); } IDictionary <string, string> queryStrings = NavigationContext.QueryString; string fileId = null; string source = null; // Photos_Extra_Viewer is deprecated //if (queryStrings.ContainsKey("token")) //{ // token = queryStrings["token"]; // source = "Photos_Extra_Viewer"; //} //else if (queryStrings.ContainsKey("Action") && queryStrings.ContainsKey("FileId")) { fileId = queryStrings["FileId"]; source = queryStrings["Action"]; } if (!string.IsNullOrEmpty(fileId)) { MediaLibrary mediaLib = new MediaLibrary(); Picture picture = mediaLib.GetPictureFromToken(fileId); currentImage = PictureDecoder.DecodeJpeg(picture.GetImage()); photoContainer.Fill = new ImageBrush { ImageSource = currentImage }; imageDetails.Text = string.Format("Image from {0}.\nPicture name:\n{1}\nMedia library token:\n{2}", source, picture.Name, fileId); } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); //Process query string IDictionary <string, string> queryStrings = this.NavigationContext.QueryString; if (NavigationContext.QueryString.Count > 0 && NavigationContext.QueryString.ContainsKey("token")) { MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(queryStrings["token"]); //Remove this query string item so that when the user clicks //"back" from the ImageEditorView page the app doesn't loop back //over to the ImageEditorView in an endless loop of navigation because //the query string value is still present and picked up by //MainPage.OnNavigateTo each time... NavigationContext.QueryString.Remove("token"); //Send Message with Picture object SetPictureAndNavigate(picture); } }
private async void SetPhotoFromEditedPage(string FiledID) { MediaLibrary library = new MediaLibrary(); Picture photoFromLibrary = library.GetPictureFromToken(FiledID); using (MemoryStream stream = new MemoryStream()) { photoFromLibrary.GetImage().CopyTo(stream); App.PhotoModel = new PhotoModel() { Buffer = stream.GetWindowsRuntimeBuffer() }; App.PhotoModel.Captured = true; App.PhotoModel.Dirty = true; Setup(); pgrAddress.Visibility = System.Windows.Visibility.Visible; await RenderAsync(); pgrAddress.Visibility = System.Windows.Visibility.Collapsed; } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { var queryString = NavigationContext.QueryString; if (_result == null && !queryString.ContainsKey("FileId") && !queryString.ContainsKey("token")) { _photoChooserTask.Show(); base.OnNavigatedTo(e); return; } _foldername.Text = NavigationContext.QueryString["path"]; if (queryString.ContainsKey("FileId")) { while (NavigationService.CanGoBack) { NavigationService.RemoveBackEntry(); } var media = new MediaLibrary(); _picture = media.GetPictureFromToken(queryString["FileId"]); _filename.Text = _picture.Name; _filename.SelectAll(); var bitmap = new BitmapImage(); bitmap.SetSource(_picture.GetImage()); _test.Source = bitmap; return; } _filename.Focus(); base.OnNavigatedTo(e); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { //Handle ExitOnBack=True arg... RscUtils.OnNavigatedTo_ExitOnBack(this.NavigationContext.QueryString); if (m_media != null) { return; } m_media = new MediaLibrary(); m_pic = null; IDictionary <string, string> parameters = this.NavigationContext.QueryString; if (parameters.ContainsKey("token")) { m_sGUID = parameters["token"]; } else if (parameters.ContainsKey("FileId")) { m_sGUID = parameters["FileId"]; } else { return; } m_pic = m_media.GetPictureFromToken(m_sGUID); if (m_pic != null) { string sFName = m_pic.Name; string sFExt = ""; int iPos = sFName.LastIndexOf('.'); if (iPos >= 0) { sFExt = sFName.Substring(iPos); sFName = sFName.Substring(0, iPos); } m_sPicFileName = m_sGUID + sFExt; m_sPhoneFolder = ""; PictureAlbum pa = m_pic.Album; for (;;) { if (pa.Name.ToString().Length == 0) { break; } if (m_sPhoneFolder.Length > 0) { m_sPhoneFolder = "\\" + m_sPhoneFolder; } m_sPhoneFolder = pa.Name + m_sPhoneFolder; pa = pa.Parent; if (pa == null) { break; } } m_sAppFolder = RscKnownFolders.GetMediaPath("Zune"); if (m_sPhoneFolder.Length > 0) { m_sAppFolder += "\\" + m_sPhoneFolder; } m_sAppPath = m_sAppFolder + "\\" + m_sPicFileName; string sNames = ""; sNames += "Name"; sNames += "\r\n"; sNames += "Time"; sNames += "\r\n"; sNames += "Size"; sNames += "\r\n"; sNames += "Folder"; m_txtName.Text = sNames; string sInf = ""; sInf += m_pic.Name; sInf += "\r\n"; sInf += m_pic.Date.ToShortDateString() + " " + m_pic.Date.ToShortTimeString(); sInf += "\r\n"; sInf += m_pic.Width.ToString() + " x " + m_pic.Height.ToString(); sInf += "\r\n"; sInf += m_sPhoneFolder; m_txtInfo.Text = sInf; m_sInf = ""; m_sInf += m_pic.Name; m_sInf += "\r\n"; m_sInf += m_sGUID; m_sInf += "\r\n"; m_sInf += m_pic.Date.ToShortDateString() + " | " + m_pic.Date.ToShortTimeString(); m_sInf += "\r\n"; m_sInf += m_pic.Width.ToString() + " x " + m_pic.Height.ToString(); m_sInf += "\r\n"; m_sInf += m_sPhoneFolder; AddSavedNote(); /* * if( bThumbnail ) * { * System.Windows.Media.Imaging.WriteableBitmap wbmp = * Microsoft.Phone.PictureDecoder.DecodeJpeg(pic.GetThumbnail(), iCX, iCY ); * * return wbmp; * } * else * { */ BitmapImage bmp = new BitmapImage(); bmp.SetSource(m_pic.GetImage()); /* * return bmp; * } */ imgFull.Source = bmp; } /* * else * { * * imgFull.Source = m_isDummy; * * } */ }
/// <summary> /// Locates a Post object and specifies the result as the page's DataContext /// </summary> private void LoadBlog() { Blog currentBlog = App.MasterViewModel.CurrentBlog; BlogName.Text = string.IsNullOrEmpty(currentBlog.BlogNameUpper) ? "" : currentBlog.BlogNameUpper; bool isSharingPhoto = (App.MasterViewModel.SharingPhotoToken != null); if (null != App.MasterViewModel.CurrentPostListItem && !isSharingPhoto) { string postId = App.MasterViewModel.CurrentPostListItem.PostId; if (App.MasterViewModel.CurrentPostListItem.DraftIndex > -1) { // Post is a local draft this.isEditingLocalDraft = true; DataContext = App.MasterViewModel.CurrentBlog.LocalPostDrafts[App.MasterViewModel.CurrentPostListItem.DraftIndex]; App.MasterViewModel.CurrentPost = App.MasterViewModel.CurrentBlog.LocalPostDrafts[App.MasterViewModel.CurrentPostListItem.DraftIndex]; setStatus(); initPostFormatUI(App.MasterViewModel.CurrentPost.PostFormat); //update the Media UI List <Media> unavaiblePictures = new List <Media>(); foreach (Media currentMedia in App.MasterViewModel.CurrentPost.Media) { using (Stream stream = currentMedia.getImageStream()) { if (stream == null) { unavaiblePictures.Add(currentMedia); continue; } try { BitmapImage image = new BitmapImage(); image.SetSource(stream); imageWrapPanel.Children.Add(BuildTappableImageElement(image, currentMedia)); } catch (Exception) { } } } if (unavaiblePictures.Count > 0) { MessageBoxResult result = MessageBox.Show("Can't read a picture attached to this draft, please try to load the draft later.", "Error", MessageBoxButton.OK); foreach (Media m in unavaiblePictures) { App.MasterViewModel.CurrentPost.Media.Remove(m); } } } else { Post post = App.MasterViewModel.CurrentPost; DataContext = post; setStatus(); initPostFormatUI(post.PostFormat); if (!string.IsNullOrWhiteSpace(post.MtKeyWords)) { tagsTextBox.Text = post.MtKeyWords; } } } else { //New post Post post = new Post(); App.MasterViewModel.CurrentPost = post; post.DateCreated = DateTime.Now; post.DateCreatedGMT = DateTime.Now.ToUniversalTime(); DataContext = post; initPostFormatUI("standard"); post.PostStatus = "publish"; setStatus(); /*postTimePicker.Value = post.DateCreated; * postDatePicker.Value = post.DateCreated;*/ if (isSharingPhoto) { MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(App.MasterViewModel.SharingPhotoToken); using (Stream pictureStream = picture.GetImage()) AddNewMediaStream(pictureStream, picture.Name); ; // clear the photo token so we don't try to add it to another post App.MasterViewModel.SharingPhotoToken = null; // blog selection page will be in the backstack, but if the user hits Back they should leave the app // and return to the photo that they were sharing (e.g., so they can share it on another service) NavigationService.RemoveBackEntry(); } } this.ToggleGalleryControlsVisibility(); }
/// <summary> /// Retrieves a picture from the device's media library based on a picture token. /// </summary> /// <param name="token">The picture token.</param> /// <returns>The <see cref="Picture"/> object that matches the supplied picture token.</returns> public Picture GetPictureFromToken(string token) { return(_mediaLibrary.GetPictureFromToken(token)); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { // Get a dictionary of query string keys and values. var queryStrings = NavigationContext.QueryString; // Ensure that there is at least one key in the query string, and check whether the "token" key is present. if (queryStrings.ContainsKey("token")) { _navigatedFrom = "Share"; if (App.ViewModel.Attachments == null || (App.ViewModel.Attachments != null && App.ViewModel.Attachments.Count < 6)) { // Retrieve the photo from the media library using the token passed to the app. var library = new MediaLibrary(); var photoFromLibrary = library.GetPictureFromToken(queryStrings["token"]); // Create a BitmapImage object and add set it as the image control source. // To retrieve a full-resolution image, use the GetImage() method instead. var fileName = Path.GetFileName(photoFromLibrary.Name); fileName = new TimeSpan(DateTime.Now.Ticks - DateTime.MinValue.Ticks).TotalMilliseconds + fileName; App.ViewModel.AddAttachment(photoFromLibrary.GetPreviewImage(), fileName, RayzItAttachment.ContentType.Image); } else { Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show("Photo could not be attached. Limit exceeded.", "Warning", MessageBoxButton.OK)); } NavigationContext.QueryString.Clear(); } if (queryStrings.ContainsKey("FileId")) { _navigatedFrom = "Share"; if (App.ViewModel.Attachments == null || (App.ViewModel.Attachments != null && App.ViewModel.Attachments.Count < 6)) { // Retrieve the photo from the media library using the token passed to the app. var library = new MediaLibrary(); var photoFromLibrary = library.GetPictureFromToken(queryStrings["FileId"]); // Create a BitmapImage object and add set it as the image control source. // To retrieve a full-resolution image, use the GetImage() method instead. var fileName = Path.GetFileName(photoFromLibrary.Name); fileName = new TimeSpan(DateTime.Now.Ticks - DateTime.MinValue.Ticks).TotalMilliseconds + fileName; App.ViewModel.AddAttachment(photoFromLibrary.GetPreviewImage(), fileName, RayzItAttachment.ContentType.Image); } else { Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show("Photo could not be attached. Limit exceeded.", "Warning", MessageBoxButton.OK)); } NavigationContext.QueryString.Clear(); } string msg; if (queryStrings.TryGetValue("NavigatedFrom", out msg)) { _navigatedFrom = msg; NavigationContext.QueryString.Clear(); } UpdateAttachmentsVisibility(); UpdateApplicationBar(); UpdateRayzHint(); FocusTextBox(); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { //MessageBox.Show("NavMode:" + e.NavigationMode.ToString()); //MessageBox.Show("Initiator:" + e.IsNavigationInitiator); //Did we get deep linked to? // Get a dictionary of query string keys and values. IDictionary <string, string> queryStrings = this.NavigationContext.QueryString; if (System.Diagnostics.Debugger.IsAttached) { imageControl.Image = new BitmapImage(new Uri("Images/BigImage.jpg", UriKind.Relative)); } if (queryStrings.ContainsKey("token")) { // Retrieve the picture from the media library using the token passed to the application. MediaLibrary library = new MediaLibrary(); Picture picture = library.GetPictureFromToken(queryStrings["token"]); // Create a WriteableBitmap object and add it to the Image control Source property. Stream s = picture.GetImage(); JpegInfo info = ExifLib.ExifReader.ReadJpeg(s, "magic.jpg"); var _width = info.Width; var _height = info.Height; var _orientation = info.Orientation; var _angle = 0; switch (info.Orientation) { case ExifOrientation.TopLeft: case ExifOrientation.Undefined: _angle = 0; break; case ExifOrientation.TopRight: _angle = 90; break; case ExifOrientation.BottomRight: _angle = 180; break; case ExifOrientation.BottomLeft: _angle = 270; break; } s.Seek(0, SeekOrigin.Begin); //DEBUG //MessageBox.Show("Angle: " + _angle); //Stream resultStream; //if (_angle > 0d) //{ // resultStream = RotateStream(s, _angle); //} //else //{ // resultStream = s; //} BitmapImage bitmap = new BitmapImage(); bitmap.CreateOptions = BitmapCreateOptions.None; bitmap.SetSource(s); this.imageControl.RenderTransformOrigin = new Point(0.5, 0.5); this.imageControl.Angle = _angle; this.imageControl.Image = bitmap; } base.OnNavigatedTo(e); }