/// <summary> /// Handles the Click event of the SaveCreenButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void SaveScreenButton_Click(object sender, RoutedEventArgs e) { // Use extension methods to convert any framework element to an extended // image instance. ExtendedImage extendedImage = Area.ToImage(); SaveFileDialog saveFileDialog = new SaveFileDialog(); // Open a file stream using the save file dialog. Only allow defining png or jpeg files. // Gif files are not supported by image tools and bmp makes no sense in the most scenarios. saveFileDialog.Filter = "Image Files (*.png, *.jpg)|*.png;*.jpg"; if (saveFileDialog.ShowDialog() == true) { using (Stream stream = saveFileDialog.OpenFile()) { // Use the write to stream extension method to write the image to the specified stream. // The image encoder is selected by the extension of the name of the image. extendedImage.WriteToStream(stream, saveFileDialog.SafeFileName); } } }
//--------------------------------------------------------------------------------------------------------- #endregion #region Tiles erstellen //Tiles erstellem //--------------------------------------------------------------------------------------------------------- void CreateTiles() { //Erstes Tile erstellen WriteableBitmap FirstTile = new WriteableBitmap(336, 336); WriteableBitmap FirstTileIcon = new WriteableBitmap(336, 336); // Wenn nicht transparent if (TileBackgroundColor != "*" & TileBackgroundColor != null) { //Hintergrundfarbe einfügen FirstTile.Clear(ConvertToSolidColorBrush(TileBackgroundColor, -1).Color); } //Tile Bild laden using (Stream input = Application.GetResourceStream(new Uri("TileMedium.png", UriKind.Relative)).Stream) { FirstTileIcon.SetSource(input); } //Bild zusammensetzen FirstTile.Blit(new Rect(0, 0, 336, 336), FirstTileIcon, new Rect(0, 0, 336, 336)); // Bild erstellen Grid grid = new Grid { Width = 336, Height = 336 }; Image img = new Image(); img.Source = FirstTile; grid.Children.Add(img); // Writeable Bitmap aus Grid erstellen WriteableBitmap wbmp = new WriteableBitmap(grid, null); // Extended Image aus Writeable Bitmap erstellen ExtendedImage extendImage = wbmp.ToImage(); // Bild speichern using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists("Shared/ShellContent/First336.png")) { store.DeleteFile("Shared/ShellContent/First336.png"); } using (var stream = store.OpenFile("Shared/ShellContent/First336.png", System.IO.FileMode.OpenOrCreate)) { extendImage.WriteToStream(stream, "Shared/ShellContent/First336.png"); } } //Bild ausgeben ImgFirstTile.Source = wbmp; //Erstes Tile groß erstellen WriteableBitmap FirstTileWidth = new WriteableBitmap(691, 336); WriteableBitmap FirstTileIconWidth = new WriteableBitmap(691, 336); // Wenn nicht transparent if (TileBackgroundColor != "*" & TileBackgroundColor != null) { //Hintergrundfarbe einfügen FirstTileWidth.Clear(ConvertToSolidColorBrush(TileBackgroundColor, -1).Color); } //Tile Bild laden using (Stream input = Application.GetResourceStream(new Uri("TileLarge.png", UriKind.Relative)).Stream) { FirstTileIconWidth.SetSource(input); } //Bild zusammensetzen FirstTileWidth.Blit(new Rect(0, 0, 691, 336), FirstTileIconWidth, new Rect(0, 0, 691, 336)); // Bild erstellen Grid gridWidth = new Grid { Width = 691, Height = 336 }; Image imgWidth = new Image(); imgWidth.Source = FirstTileWidth; gridWidth.Children.Add(imgWidth); // Writeable Bitmap aus Grid erstellen WriteableBitmap wbmpWidth = new WriteableBitmap(gridWidth, null); // Extended Image aus Writeable Bitmap erstellen ExtendedImage extendImageWidth = wbmpWidth.ToImage(); // Bild speichern using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists("Shared/ShellContent/First691.png")) { store.DeleteFile("Shared/ShellContent/First691.png"); } using (var stream = store.OpenFile("Shared/ShellContent/First691.png", System.IO.FileMode.OpenOrCreate)) { extendImageWidth.WriteToStream(stream, "Shared/ShellContent/First691.png"); } } //Zweites Tile erstellen WriteableBitmap SecondTile = new WriteableBitmap(336, 336); WriteableBitmap SecondTileIcon = new WriteableBitmap(336, 336); //Hintergrundfarbe einfügen if (SecondTileBackgroundColor != "*" & SecondTileBackgroundColor != null) { SecondTile.Clear(ConvertToSolidColorBrush(SecondTileBackgroundColor, -1).Color); } //Tile Bild laden using (Stream input = Application.GetResourceStream(new Uri("SecondTileMedium.png", UriKind.Relative)).Stream) { SecondTileIcon.SetSource(input); } //Bild zusammensetzen SecondTile.Blit(new Rect(0, 0, 336, 336), SecondTileIcon, new Rect(0, 0, 336, 336)); // Bild erstellen Grid gridSecond = new Grid { Width = 336, Height = 336 }; Image imgSecond = new Image(); imgSecond.Source = SecondTile; gridSecond.Children.Add(imgSecond); // Writeable Bitmap aus Grid erstellen WriteableBitmap wbmpSecond = new WriteableBitmap(gridSecond, null); // Extended Image aus Writeable Bitmap erstellen ExtendedImage extendImageSecond = wbmpSecond.ToImage(); // Bild speichern using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists("Shared/ShellContent/Second336.png")) { store.DeleteFile("Shared/ShellContent/Second336.png"); } using (var stream = store.OpenFile("Shared/ShellContent/Second336.png", System.IO.FileMode.OpenOrCreate)) { extendImageSecond.WriteToStream(stream, "Shared/ShellContent/Second336.png"); } } // Bild ausgeben ImgSecondTile.Source = wbmpSecond; //Zweites Tile erstellen WriteableBitmap SecondTileWidth = new WriteableBitmap(691, 336); WriteableBitmap SecondTileIconWidth = new WriteableBitmap(691, 336); //Hintergrundfarbe einfügen if (SecondTileBackgroundColor != "*" & SecondTileBackgroundColor != null) { SecondTileWidth.Clear(ConvertToSolidColorBrush(SecondTileBackgroundColor, -1).Color); } //Tile Bild laden using (Stream input = Application.GetResourceStream(new Uri("SecondTileLarge.png", UriKind.Relative)).Stream) { SecondTileIconWidth.SetSource(input); } //Bild zusammensetzen SecondTileWidth.Blit(new Rect(0, 0, 691, 336), SecondTileIconWidth, new Rect(0, 0, 691, 336)); // Second Tile groß erstellen Grid gridSecondWidth = new Grid { Width = 691, Height = 336 }; Image imgSecondWidth = new Image(); imgSecondWidth.Source = SecondTileWidth; gridSecondWidth.Children.Add(imgSecondWidth); // Writeable Bitmap aus Grid erstellen WriteableBitmap wbmpSecondWidth = new WriteableBitmap(gridSecondWidth, null); // Extended Image aus Writeable Bitmap erstellen ExtendedImage extendImageSecondWidth = wbmp.ToImage(); // Bild speichern using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!store.FileExists("Shared/ShellContent/Second691.png")) { store.DeleteFile("Shared/ShellContent/Second691.png"); } using (var stream = store.OpenFile("Shared/ShellContent/Second691.png", System.IO.FileMode.OpenOrCreate)) { extendImageSecondWidth.WriteToStream(stream, "Shared/ShellContent/Second691.png"); } } //Erstes Tile neu erstellen ShellTile Tile = ShellTile.ActiveTiles.First(); FlipTileData First = new FlipTileData(); First.Title = MyMusicPlayer.Resources.AppResources.Z001_AppTitle; First.SmallBackgroundImage = new Uri("isostore:/Shared/ShellContent/First336.png", UriKind.Absolute); First.BackgroundImage = new Uri("isostore:/Shared/ShellContent/First336.png", UriKind.Absolute); First.WideBackgroundImage = new Uri("isostore:/Shared/ShellContent/First691.png", UriKind.Absolute); Tile.Update(First); //Second Tile neu erstellen if (oTile != null && oTile.NavigationUri.ToString().Contains("flip")) { FlipTileData oFliptile = new FlipTileData(); oFliptile.Title = Title = ""; oFliptile.SmallBackgroundImage = new Uri("isostore:/Shared/ShellContent/Second336.png", UriKind.Absolute); oFliptile.BackgroundImage = new Uri("isostore:/Shared/ShellContent/Second336.png", UriKind.Absolute); oFliptile.WideBackgroundImage = new Uri("isostore:/Shared/ShellContent/Second691.png", UriKind.Absolute); oTile.Update(oFliptile); } }
public ConnectPage() { InitializeComponent(); // Sauvegarde de l'avatar dans la mémoire du téléphone _webClient = new WebClient(); _webClient.OpenReadCompleted += (s1, e1) => { if (e1.Error == null) { try { string fileName = store["userAvatarFile"] as string; bool isSpaceAvailable = IsSpaceIsAvailable(e1.Result.Length); if (isSpaceAvailable) { if (isoStore.FileExists(fileName)) { isoStore.DeleteFile(fileName); } using (var isfs = new IsolatedStorageFileStream(fileName, FileMode.CreateNew, isoStore)) { long fileLen = e1.Result.Length; byte[] b = new byte[fileLen]; e1.Result.Read(b, 0, b.Length); if (b[0] == 71 && b[1] == 73 && b[2] == 70) { // File is a GIF, we need to convert it! var image = new ExtendedImage(); var gifDecoder = new ImageTools.IO.Gif.GifDecoder(); gifDecoder.Decode(image, new MemoryStream(b)); image.WriteToStream(isfs, "avatar.png"); Dispatcher.BeginInvoke(() => { store.Remove("isConnected"); store.Add("isConnected", ""); NavigationService.Navigate(new Uri("/WelcomePage.xaml?from=connect", UriKind.Relative)); }); } else { isfs.Write(b, 0, b.Length); isfs.Flush(); Dispatcher.BeginInvoke(() => { store.Remove("isConnected"); store.Add("isConnected", ""); NavigationService.Navigate(new Uri("/WelcomePage.xaml?from=connect", UriKind.Relative)); }); } } } else { Dispatcher.BeginInvoke(() => { MessageBox.Show("Erreur lors de la première connexion. La mémoire de votre terminal semble pleine."); }); } } catch (Exception ex) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Erreur n°1 dans la sauvegarde de l'avatar : " + ex.Message); }); } } else { Dispatcher.BeginInvoke(() => { MessageBox.Show("Erreur n°2 dans la sauvegarde de l'avatar : " + e1.Error.Message); }); } }; }