canWrite() private method

private canWrite ( ) : bool
return bool
Example #1
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.getAtomCount() == 0)
            {
                return(null);
            }

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

            sun.awt.Win32FontManager w32Font = new sun.awt.Win32FontManager(); // need this for class to be found

            Environment.SetEnvironmentVariable("CLASSPATH", ".", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("JAVA_HOME", @"C:\Mobius_OpenSource\MobiusCommon\CdkMx\bin\Debug", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("Path", @"%JAVA_HOME%", EnvironmentVariableTarget.Process);

            /* Need following?
             * CLASSPATH=.; / JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21 / Path=%JAVA_HOME%\bin;
             */

            //DecimalFormatSymbols.getInstance(Local.ENGLISH);

            //Locale.forLanguageTag("en-US")

            DepictionGenerator dptgen = new DepictionGenerator();

            dptgen.withSize(bitmapWidth, bitmapHeight);        // px (raster) or mm (vector)
            //dptgen.withMolTitle();
            //dptgen.withTitleColor(Color.DarkGray); // annotations are red by default
            Depiction d = dptgen.depict(NativeMol);

            /*
             *
             * public const string SVG_FMT = "svg";
             * public const string PS_FMT = "ps";
             * public const string EPS_FMT = "eps";
             * public const string PDF_FMT = "pdf";
             * public const string JPG_FMT = "jpg";
             * public const string PNG_FMT = "png";
             * public const string GIF_FMT = "gif";
             *
             * public const string UNITS_MM = "mm";
             * public const string UNITS_PX = "px";
             */
            java.util.List formats = d.listFormats();
            java.io.File   file    = new java.io.File(@"c:\downloads\test.jpg");
            bool           b       = file.canWrite();
            string         s       = d.toSvgStr();

            d.writeTo("jpg", file);
            //d.writeTo("svg", @"c:\downloads\test.svg");

            //string svg = d.toSvgStr();
            //bm = SvgUtil.GetBitmapFromSvgXml(svg, bitmapWidth);
            bm = new Bitmap(@"c:\downloads\test.jpg");
            return(bm);
        }