当前位置: 首页>>代码示例>>C#>>正文


C# Map.Write方法代码示例

本文整理汇总了C#中Map.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Map.Write方法的具体用法?C# Map.Write怎么用?C# Map.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Map的用法示例。


在下文中一共展示了Map.Write方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunFromArgs

        public override void RunFromArgs(string[] args)
        {
            string outName = null;
            bool reverseOrder = false;

            OptionSet optionSet = new OptionSet()
            {
                {"o|out=", x => outName = x},
                {"r|reverse", x => reverseOrder = true}
            };

            List<string> mapNames = optionSet.Parse(args);

            if (mapNames.Count == 0)
            {
                throw new ApplicationException(Resources.NoMapsSpecified);
            }

            foreach (string mapName in mapNames)
            {
                string formattedMapName = FormatFolderPath(mapName);
                string writeTo = outName;
                if (String.IsNullOrEmpty(writeTo))
                {
                    writeTo = mapName;
                }
                writeTo = FormatFolderPath(writeTo, Path.GetFileNameWithoutExtension(formattedMapName));

                IMap map;
                try
                {
                    Console.WriteLine(String.Format(Resources.ReadingMap, formattedMapName));
                    map = new Map(ReadAllBytes(formattedMapName));
                }
                catch (FileNotFoundException)
                {
                    string fullPath = Path.GetFullPath(formattedMapName);
                    throw new ApplicationException(String.Format(Resources.MapDoesNotExist, fullPath));
                }

                if (!reverseOrder)
                {
                    Console.WriteLine(Resources.SortingLayers);
                    map.Layers.Sort((a, b) => a.Name.CompareTo(b.Name));
                }
                else
                {
                    Console.WriteLine(Resources.SortingLayersInReverse);
                    map.Layers.Sort((a, b) => b.Name.CompareTo(a.Name));
                }

                Console.WriteLine(String.Format(Resources.WritingMap, writeTo));
                WriteAllBytes(writeTo, map.Write());
            }
        }
开发者ID:DamienHauta,项目名称:NS2-Map-Extract,代码行数:55,代码来源:Program.cs

示例2: FindPurpleByValue

        public void FindPurpleByValue()
        {
            Map map = new Map(new GDIPlus_TextMetrics(), null);
            using (map.Write()) {
                map.AddColor("Purple 50%", 14, 0, 0.5F, 0, 0, false);
                map.AddColor("Purplicious", 11, 0.2F, 1F, 0.1F, 0.08F, false);
                map.AddColor("Blue", 12, 0.95F, 0.35F, 0, 0, false);
                map.AddColor("Black", 88, 0, 0, 0, 1F, false);
            }

            short ocadId;
            float c, m, y, k;
            List<SymColor> colorList;
            using (map.Read())
                colorList = new List<SymColor>(map.AllColors);

            Assert.IsTrue(FindPurple.FindPurpleColor(colorList, out ocadId, out c, out m, out y, out k));
            Assert.AreEqual(11, ocadId);
            Assert.AreEqual(0.2F, c);
            Assert.AreEqual(1F, m);
            Assert.AreEqual(0.1F, y);
            Assert.AreEqual(0.08F, k);
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:23,代码来源:FindPurpleTests.cs

示例3: RenderToMapThenToBitmap

        // Render a description to a map, then to a bitmap for testing purposes. Hardcoded 6 mm box size.
        internal static Bitmap RenderToMapThenToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);
            descriptionRenderer.Description = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize = 6.0F;
            descriptionRenderer.Margin = 0.7F;
            descriptionRenderer.NumberOfColumns = numColumns;
            PointF location = new PointF(30, -100);

            SizeF size = descriptionRenderer.Measure();

            Bitmap bm = new Bitmap((int) size.Width * 8, (int) size.Height * 8);
            Graphics g = Graphics.FromImage(bm);
            g.ScaleTransform(bm.Width / size.Width, -bm.Height / size.Height);
            g.TranslateTransform(-location.X, -location.Y);

            g.Clear(Color.White);

            Map map = new Map(new GDIPlus_TextMetrics(), null);
            using (map.Write()) {
                Dictionary<object, SymDef> dict = new Dictionary<object, SymDef>();

                // Create white color and white-out symdef.
                SymColor white = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[CourseLayout.KeyWhiteOut] = whiteArea;

                SymColor color = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                descriptionRenderer.RenderToMap(map, color, location, dict);
            }

            InputOutput.WriteFile(TestUtil.GetTestFile("descriptions\\desc_temp.ocd"), map, new MapFileFormat(MapFileFormatKind.OCAD, 8));

            using (map.Read()) {
                RenderOptions renderOpts = new RenderOptions();
                renderOpts.usePatternBitmaps = true;
                renderOpts.minResolution = 0.1F;
                renderOpts.renderTemplates = RenderTemplateOption.MapAndTemplates;
                map.Draw(new GDIPlus_GraphicsTarget(g), new RectangleF(location.X, location.Y - size.Height, size.Width, size.Height), renderOpts, null);
            }

            g.Dispose();

            return bm;
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:49,代码来源:DescriptionRendererTests.cs

示例4: NoPurple

        public void NoPurple()
        {
            Map map = new Map(new GDIPlus_TextMetrics(), null);
            using (map.Write()) {
                map.AddColor("Yellow", 11, 0.0F, 0.25F, 0.79F, 0.08F, false);
                map.AddColor("Blue", 12, 0.95F, 0.35F, 0, 0, false);
                map.AddColor("Black", 88, 0, 0, 0, 1F, false);
            }

            short ocadId;
            float c, m, y, k;
            List<SymColor> colorList;
            using (map.Read())
                colorList = new List<SymColor>(map.AllColors);

            Assert.IsFalse(FindPurple.FindPurpleColor(colorList, out ocadId, out c, out m, out y, out k));
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:17,代码来源:FindPurpleTests.cs

示例5: RenderSymbolToMap

        // Test for rendering into a map.
        // Render one course object to a map.
        internal Map RenderSymbolToMap(Symbol sym, float boxSize)
        {
            Map map = new Map(new GDIPlus_TextMetrics(), null);

            using (map.Write()) {
                //Dictionary<object, SymDef> dict = new Dictionary<object, SymDef>();
                SymColor symColor = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                PointSymDef symdef = sym.CreateSymdef(map, symColor, boxSize);
                PointSymbol symbol = new PointSymbol(symdef, new PointF(0,0), 0, null);
                map.AddSymbol(symbol);
            }
            return map;
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:15,代码来源:SymbolDBTests.cs

示例6: WriteImageBitmaps

        // Write all the image bitmaps. Also updates the file names in the templates to the full path names.
        private void WriteImageBitmaps(Map map)
        {
            using (map.Write()) {
                List<TemplateInfo> templates = new List<TemplateInfo>(map.Templates);

                foreach (BitmapToWrite bitmapToWrite in BitmapsToWrite()) {
                    BitmapUtil.SaveBitmap(bitmapToWrite.Bitmap, bitmapToWrite.FullPath, bitmapToWrite.Format);

                    for (int i = 0; i < templates.Count; ++i) {
                        if (templates[i].absoluteFileName == bitmapToWrite.Name)
                            templates[i] = templates[i].UpdateFileName(bitmapToWrite.FullPath);
                    }
                }

                map.Templates = templates;
            }
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:18,代码来源:OcadCreation.cs

示例7: ConvertToLevel

        protected void ConvertToLevel(string jsonPath, string levelPath, string outPath)
        {
            Console.WriteLine("LEVEL " + outPath + " " + jsonPath + " " + levelPath);
            IMap map = new Map(File.ReadAllBytes(levelPath));
            string jsonStr = File.ReadAllText(jsonPath);

            JsonMapParser jsonMapParser = new JsonMapParser();
            jsonMapParser.ImportJson(map, jsonStr);

            Directory.CreateDirectory(Path.GetDirectoryName(outPath));
            File.WriteAllBytes(outPath, map.Write());
        }
开发者ID:DamienHauta,项目名称:NS2-Map-Extract,代码行数:12,代码来源:MapConverter.cs

示例8: OnChangeJson

        public void OnChangeJson(string path)
        {
            string levelPath;
            string jsonPath;
            DateTime saveTime;
            string backupDir;
            bool createBackups;
            lock (ThreadLock)
            {
                createBackups = CreateBackups;
                backupDir = BackupDir;
                levelPath = LevelPath;
                jsonPath = JsonPath;
                saveTime = saveLevelTime;
            }

            ThreadPool.QueueUserWorkItem((object state) =>
            {
                lock (ThreadLock)
                {
                    if (saveTime == null || (DateTime.Now - saveTime).TotalMilliseconds > 50)
                    {
                        if (createBackups && !String.IsNullOrWhiteSpace(backupDir))
                        {
                            Directory.CreateDirectory(backupDir);
                            string levelName = Path.GetFileName(LevelPath);
                            string backup = MapUtils.FindNextFileVersionName(Path.Combine(backupDir, levelName));
                            OnEvent(String.Format("Creating backup at '{0}'", backup));
                            File.Copy(levelPath, backup);
                        }
                        OnEvent(String.Format("Parsing '{0}'", jsonPath));


                        IMap map = new Map(File.ReadAllBytes(levelPath));
                        string jsonStr = File.ReadAllText(path);

                        JsonMapParser jsonMapParser = new JsonMapParser();
                        jsonMapParser.ImportJson(map, jsonStr);

                        OnEvent(String.Format("Rebuilding '{0}'", Path.GetFileName(levelPath)));

                        Directory.CreateDirectory(Path.GetDirectoryName(levelPath));
                        File.WriteAllBytes(levelPath, map.Write());

                        OnEvent(String.Format("Finished rebuilding '{0}'", Path.GetFileName(levelPath)));

                        
                        saveJsonTime = DateTime.Now;
                    }
                }
            });
        }
开发者ID:DamienHauta,项目名称:NS2-Map-Extract,代码行数:52,代码来源:UpdateResponder.cs

示例9: CreateOcadFiles

        // Create some courses, write them, and check against a dump.
        void CreateOcadFiles(OcadCreationSettings settings, string[] expectedOcadFiles, params RectangleF[] expectedPrintRectangles)
        {
            for (int i = 0; i < expectedOcadFiles.Length; ++i) {
                File.Delete(expectedOcadFiles[i]);
            }

            bool success = controller.CreateOcadFiles(settings);
            Assert.IsTrue(success);

            for (int i = 0; i < expectedOcadFiles.Length; ++i) {
                Map newMap = new Map(new GDIPlus_TextMetrics(), null);
                using (newMap.Write())
                    InputOutput.ReadFile(expectedOcadFiles[i], newMap);
                using (newMap.Read())
                    TestUtil.AssertEqualRect(expectedPrintRectangles[i], newMap.PrintArea, 0.01F, "ocad imported print area");
            }
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:18,代码来源:SetPrintAreaTests.cs

示例10: RenderCourseObjToMap

        // Render one course object to a map.
        internal Map RenderCourseObjToMap(CourseObj courseobj)
        {
            Map map = new Map(new GDIPlus_TextMetrics(), null);

            using (map.Write()) {
                Dictionary<object, SymDef> dict = new Dictionary<object, SymDef>();

                // Create white color and white-out symdef.
                SymColor white = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[CourseLayout.KeyWhiteOut] = whiteArea;

                // Create layout symdef.
                ImageSymDef layoutSymDef = new ImageSymDef(SymLayer.Layout);
                map.AddSymdef(layoutSymDef);
                dict[CourseLayout.KeyLayout] = layoutSymDef;

                SymColor symColor = null;
                SpecialColor specialColor = courseobj.CustomColor ?? SpecialColor.Purple;
                switch (specialColor.Kind) {
                    case SpecialColor.ColorKind.Black:
                        symColor = map.AddColor("Black", 1, 0, 0, 0, 1F, false);
                        break;
                    case SpecialColor.ColorKind.Purple:
                        symColor = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                        break;
                    case SpecialColor.ColorKind.Custom:
                        CmykColor cmyk = specialColor.CustomColor;
                        symColor = map.AddColor("Custom", 61, cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black, false);
                        break;
                }

                courseobj.AddToMap(map, symColor, dict);

                // Make drop targets visible for debugging.
                foreach (SymDef symdef in map.AllSymdefs) {
                    if (symdef.SymbolId == "781")
                        map.SetSymdefVisible(symdef, true);
                }
            }
            return map;
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:45,代码来源:CourseObjTests.cs


注:本文中的Map.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。