public void btnEditTitle_Click(object sender, RoutedEventArgs e) { int selected_index = listView.SelectedIndex; if (selected_index < 0) { return; } save_popup popup = new save_popup(); if (popup.ShowDialog() == true) { string compositions_path = SoufTools.compositions_path; string old_filename = composition_names[selected_index]; string new_filename = popup.FileName; string old_path = Path.Combine(compositions_path, old_filename); string new_path = Path.Combine(compositions_path, new_filename); File.Move(old_path + ".png", new_path + ".png"); File.Move(old_path + ".json", new_path + ".json"); UpdateList(); } }
public void save_Composition(object sender, MouseButtonEventArgs e) { save_popup popup = new save_popup(); if (popup.ShowDialog() == true) { string path_filename = Path.Combine(SoufTools.compositions_path, popup.FileName); // Creating the JSON file PlankInfo[] plankinfos = new PlankInfo[planks.Count]; for (int i = 0; i < planks.Count; i++) { Rectangle r = planks[i].r; var width = r.Width / SoufTools.GRID_SIZE; var height = r.Height / SoufTools.GRID_SIZE; double plank_x = Canvas.GetLeft(r); double plank_y = Canvas.GetTop(r); plankinfos[i] = new PlankInfo() { Width = width, Height = height, X = plank_x, Y = plank_y }; } string strResultJson = JsonConvert.SerializeObject(plankinfos); SoufTools.CreateFile(path_filename + ".json", strResultJson); // Creating an Image RenderTargetBitmap rtb = new RenderTargetBitmap((int)canvas.ActualWidth, (int)canvas.ActualHeight, 96, 96, PixelFormats.Pbgra32); rtb.Render(canvas); using (FileStream stream = new FileStream(path_filename + ".png", FileMode.Create)) { PngBitmapEncoder encoder5 = new PngBitmapEncoder(); encoder5.Frames.Add(BitmapFrame.Create(rtb)); encoder5.Save(stream); } } }