/// <summary> /// Get a bitmap of the specified KekuleJs in the specified size /// </summary> /// <param name="mol"></param> /// <param name="size"></param> /// <returns></returns> public Bitmap GetBitmap( string molfile, Size size) { try { Bitmap bm = null; LoadInitialPage(); // be sure initial page is loaded if (Debug) { DebugLog.Message("GetBitmap Entered: " + molfile + ", " + size + IdText); } Stopwatch sw = Stopwatch.StartNew(); string key = string.Format("GetMolfileBitmap({0}, {1}, {2})", molfile, size.Width, size.Height); if (CacheMx <Bitmap> .TryGetValue(key, out bm)) { return(bm); } SetMoleculeAndRender(molfile, size); // render the structure bm = new Bitmap(Browser.Width, Browser.Height); Rectangle rt = new Rectangle(0, 0, Browser.Width, Browser.Height); Browser.DrawToBitmap(bm, rt); if (bm.Width > 1) { CacheMx <Bitmap> .Add(key, bm); } GetBitmapCount++; if (Debug) { DebugLog.StopwatchMessage("GetBitmap Complete, Time: ", sw); } return(bm); } catch (Exception ex) { return(new Bitmap(1, 1)); // failed for some reason } }
/// <summary> /// Get SVG of the specified KekuleJs /// </summary> /// <param name="KekuleJs"></param> /// <param name="size"></param> /// <returns></returns> public string GetSvg( string KekuleJs, Size size) { string svg = null; string key = string.Format("GetMolfileSvg({0}, {1}, {2})", KekuleJs, size.Width, size.Height); if (CacheMx <string> .TryGetValue(key, out svg)) { return(svg); } LoadInitialPage(); // be sure initial page is loaded if (Debug) { DebugLog.Message("GetSvg Entered: " + KekuleJs + ", " + size + IdText); } Stopwatch sw = Stopwatch.StartNew(); SetMoleculeAndRender(KekuleJs, size); // render the structure ExecuteJavaScript("function getSvgString() { return jsd.getSvg(); };"); // define function to get the SVG svg = CallJavaScriptMethod("getSvgString"); // call the function to get the SVG if (Lex.IsDefined(svg)) { CacheMx <string> .Add(key, svg); } GetSvgCount++; if (Debug) { DebugLog.StopwatchMessage("GetSvg Complete, Length: " + Lex.GetStringLength(svg) + ", Time: ", sw); } return(svg); }