private void CopyChatURLClick(object sender, RoutedEventArgs e) { if (StudioContext.IsProjectLoaded(true)) { Clipboard.SetText(StudioContext.CurrentProjectUrl()); } }
private void StartChatInSimulator() { if (StudioContext.IsProjectLoaded(true)) { Process.Start("anaconsim://app?chatflow=" + Uri.EscapeDataString(StudioContext.CurrentProjectUrl())); } }
public void ExportUIElementAsImage(UIElement element, Rect cropRect) { //Add some margin to the image cropRect.Inflate(cropRect.Width / 40, cropRect.Height / 40); if (!StudioContext.IsProjectLoaded(true)) { return; } var currentProj = StudioContext.CurrentProject(); var resolution = 200; var scale = resolution / 96d; var target = new RenderTargetBitmap((int)(scale * (element.RenderSize.Width)), (int)(scale * (element.RenderSize.Height)), scale * 96, scale * 96, PixelFormats.Pbgra32); target.Render(element); var encoder = new PngBitmapEncoder(); var outputFrame = BitmapFrame.Create(target); encoder.Frames.Add(outputFrame); var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "ANA Conversation Studio"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var fileName = currentProj.Name + " " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".png"; var fullPath = Path.Combine(dir, fileName); using (var ms = new MemoryStream()) { encoder.Save(ms); ms.Position = 0; var bmp = new System.Drawing.Bitmap(ms); var croppedBmp = CropImage(bmp, new System.Drawing.Rectangle((int)(cropRect.X * scale), (int)(cropRect.Y * scale), (int)(cropRect.Width * scale), (int)(cropRect.Height * scale))); using (var file = File.OpenWrite(fullPath)) croppedBmp.Save(file, System.Drawing.Imaging.ImageFormat.Jpeg); } Process.Start("explorer", "/select," + fullPath); }