コード例 #1
0
ファイル: Depiction_Example.cs プロジェクト: roddickchen/NCDK
        public void Main()
        {
            Depiction depiction = null;

            #region EnsureSuffix
            depiction.WriteTo(Depiction.SvgFormatKey, "~/chemical"); // create a file "~/chemical.svg"
            #endregion
        }
コード例 #2
0
        /// <summary>
        /// Render molecule into bitmap of specified size.
        /// </summary>
        /// <param name="bitmapWidth"></param>
        /// <param name="bitmapHeight"></param>
        /// <param name="dp"></param>
        /// <returns></returns>

        public Bitmap GetMoleculeBitmap(
            int bitmapWidth,
            int bitmapHeight,
            DisplayPreferences dp = null)
        {
            byte[]     ba;
            FileStream fs;
            float      top, bottom, left, right, height, width, strBottom, hCenter, drop, stdBndLen, scale, fontSize, bondThickness;
            int        txtLen;
            Bitmap     bm;

            UpdateNativeMolecule();

            if (NativeMol == null || NativeMol.Atoms.Count == 0)
            {
                return(null);
            }

            //NativeMol.setProperty(CDKConstants.TITLE, "caffeine"); // title already set from input!

            DepictionGenerator dptgen = new DepictionGenerator();

            dptgen.Size = new System.Windows.Size(bitmapWidth, bitmapHeight);

            Depiction d = dptgen.Depict(NativeMol);

            dptgen.Size      = new System.Windows.Size(bitmapWidth, bitmapHeight);
            dptgen.FillToFit = true;

            //string svg = d.ToSvgString();
            //bm = SvgUtil.GetBitmapFromSvgXml(svg, bitmapWidth);

            //System.Windows.Media.Imaging.RenderTargetBitmap rtBm = d.ToBitmap();

            string path = TempFile.GetTempFileName(ClientDirs.TempDir, "jpg", true);

            d.WriteTo("jpg", path);
            bm = new Bitmap(path);

            return(bm);
        }
コード例 #3
0
        public void Generate(string text, string filename)
        {
            Depiction depict = null;

            if (IsReactionSmilees(text))
            {
                var rxn = parser.ParseReactionSmiles(text);
                ReactionManipulator.PerceiveDativeBonds(rxn);
                ReactionManipulator.PerceiveRadicals(rxn);
                depict = PictureGenerator.Depict(rxn);
            }
            else
            {
                var mol = NCDKExcel.Utility.Parse(text);
                AtomContainerManipulator.PerceiveDativeBonds(mol);
                AtomContainerManipulator.PerceiveRadicals(mol);
                depict = PictureGenerator.Depict(mol);
            }
            depict.WriteTo(filename);

            if (!filename.EndsWith(".svg"))
            {
                return;
            }

            string svg;

            using (var r = new StreamReader(filename))
            {
                svg = r.ReadToEnd();
            }
            using (var r = new StreamWriter(filename))
            {
                r.Write(_rect_transparent.Replace(svg, ""));
            }
        }