internal void SaveChangesToImage(InkPresenter ImageArea) { if (this.IsEditable) { WriteableBitmap wbBitmap = new WriteableBitmap(ImageArea, new TranslateTransform()); using (var stream = new MemoryStream()) { wbBitmap.WritePNG(stream); stream.Seek(0, System.IO.SeekOrigin.Begin); byte[] imageBytes = new byte[stream.Length]; stream.Read(imageBytes, 0, (int)stream.Length); this.FeedbackImage.DataBytes = imageBytes; } ImageArea.Strokes.Clear(); } }
protected static string WriteTileToDisk(string year, string description, int width, int height, string fontSize, Thickness margins) { Grid container = new Grid() { Width = width, Height = height, Background = (Brush)Application.Current.Resources["TransparentBrush"] }; container.Children.Add(GetTextBlockToRender(description, fontSize, margins)); // Force the container to render itself container.UpdateLayout(); container.Arrange(new Rect(0, 0, width, height)); var writeableBitmap = new WriteableBitmap(container, null); string fileName = SharedImagePath + "tile" + height + width + ".png"; using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var stream = new IsolatedStorageFileStream(fileName, FileMode.Create, storage)) { if (writeableBitmap.PixelHeight > 0) { writeableBitmap.WritePNG(stream); } } } return fileName; }
internal async Task ShowPhotoResult(PhotoResult result) { var imageVM = new FeedbackImageVM(this.ParentVM); imageVM.IsEditable = true; byte[] imageBytes = null; if (Path.GetExtension(result.OriginalFileName).ToLower().EndsWith("jpg")) { BitmapImage img = new BitmapImage(); img.SetSource(result.ChosenPhoto); var wbBitmap = new WriteableBitmap(img); using (var stream = new MemoryStream()) { wbBitmap.WritePNG(stream); stream.Seek(0, System.IO.SeekOrigin.Begin); imageBytes = new byte[stream.Length]; stream.Read(imageBytes, 0, (int)stream.Length); } } else //png { imageBytes = new byte[result.ChosenPhoto.Length]; await result.ChosenPhoto.ReadAsync(imageBytes, 0, (int)result.ChosenPhoto.Length); } imageVM.FeedbackImage = new FeedbackAttachment(Path.GetFileName(result.OriginalFileName), imageBytes, null); Attachments.Add(imageVM); this.ParentVM.SwitchToImageEditor(imageVM); }
private void PinButton_Click(object sender, EventArgs e) { if (id == null) { id = DateTime.Now.Ticks.ToString(); } // save sticky settings[id] = Sticky; WriteableBitmap front = new WriteableBitmap(TilePreview, null); CompensateForRender(front.Pixels); string frontFilename = GetTileFilename(id); using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fs = isf.CreateFile(frontFilename)) { front.WritePNG(fs); } } StandardTileData tile = new StandardTileData { BackgroundImage = new Uri("isostore:/" + frontFilename), BackBackgroundImage = new Uri("IDontExist", UriKind.Relative), // UGLY HACK BackContent = string.Empty, BackTitle = string.Empty }; if (EnableBack.IsChecked.GetValueOrDefault()) { FlurryWP7SDK.Api.LogEvent("Enabling tile"); WriteableBitmap back = new WriteableBitmap(BackTilePreview, null); CompensateForRender(back.Pixels); string backFilename = GetTileFilename(id, true); using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fs = isf.CreateFile(backFilename)) { back.WritePNG(fs); } } tile.BackBackgroundImage = new Uri("isostore:/" + backFilename); } var shelltile = GetTile(id); if (shelltile != null) { FlurryWP7SDK.Api.LogEvent("Updated existing tile"); shelltile.Update(tile); Focus(); MessageBox.Show("Your updated tile should be in your start screen.", "Tile updated", MessageBoxButton.OK); } else { FlurryWP7SDK.Api.LogEvent("Pinned new tile"); ShellTile.Create(GetTileUri(id), tile); } }