public IClipboardObject AddAsHtml(FrameworkElement fe, Size imageSize, Size imageElementSize) { if (fe == null) throw new NullReferenceException(nameof(fe)); var bmp = fe.RenderToBitmap(imageSize); var img_src = string.Empty; var use_inline_image = false; if (use_inline_image) { // Inline images are not actually supported by Office applications, so don't use it. // maybe in future... var img_data = bmp.ToBitmap().ToArray(); var base64_img_data = Convert.ToBase64String(img_data); img_src = $"data:image/png;charset=utf-8;base64, {base64_img_data}"; } else { // create a temp file with image and use it as a source var tmp = Path.GetTempFileName(); bmp.Save(tmp); img_src = new Uri(tmp, UriKind.Absolute).ToString(); } var html_data = CF_HTML.PrepareHtmlFragment($"<img height=\"{imageElementSize.Height}\" width=\"{imageElementSize.Width}\" src=\"{img_src}\" />"); Data.SetData(DataFormats.Html, html_data); return this; }
public IClipboardObject Add(FrameworkElement fe, Size size) { if (fe == null) throw new NullReferenceException(nameof(fe)); var bmp = fe.RenderToBitmap(size); var mf = bmp.CreateMetafile(); Data.SetData(DataFormats.EnhancedMetafile, mf); return this; }