Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string target = this.tbxInput.Text;
            string cat = this.tbxSet.Text;
            int size = int.Parse(this.tbxSize.Text);
            string pdf = this.tbxOutput.Text;
            int labelsize = int.Parse(this.tbxLabelSize.Text);
            int lwidth = int.Parse(this.tbxWidth.Text);
            int label_h = labelsize;
            int size_w = size;
            int size_h = size + label_h;
            List<string> pdfpages = new List<string>();

            IPageLayout3 layout = new PageLayoutClass();
            IGraphicsContainer con = layout as IGraphicsContainer;
            IPage page = layout.Page;
            page.FormID = esriPageFormID.esriPageFormA4;
            page.Units = esriUnits.esriPoints;
            double width;
            double height;
            page.QuerySize(out width, out height);
            int col = (int)Math.Floor(width / size_w);
            int row = (int)Math.Floor(height / size_h);

            IStyleGalleryStorage sgs = new StyleGalleryClass();
            while (sgs.FileCount > 0)
            {
                sgs.RemoveFile(sgs.get_File(0));
            }
            IStyleGallery sg = sgs as IStyleGallery;
            sgs.AddFile(target);
            sgs.TargetFile = target;
            if (cbPoint.Checked)
            {
                List<string> ps = ExportSymbol(sg, "Marker Symbols", col, row, size, lwidth,labelsize, label_h, size_w, size_h, height, cat, layout);
                pdfpages.AddRange(ps);
            }
            if(cbLine.Checked)
            {
                List<string> ps = ExportSymbol(sg, "Line Symbols", col, row, size, lwidth, labelsize, label_h, size_w, size_h, height, cat, layout);
                pdfpages.AddRange(ps);
            }
            if (cbArea.Checked)
            {
                List<string> ps = ExportSymbol(sg, "Fill Symbols", col, row, size, lwidth, labelsize, label_h, size_w, size_h, height, cat, layout);
                pdfpages.AddRange(ps);
            }

            PdfDocument doc = new PdfDocument();
            foreach (string temp in pdfpages)
            {
                PdfDocument temp_doc = PdfReader.Open(temp, PdfDocumentOpenMode.Import);
                doc.AddPage(temp_doc.Pages[0]);
            }
            if (doc.PageCount > 0)
            {
                doc.Save(pdf);
            }
            doc.Close();
            MessageBox.Show("成功生成符号图集");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string input = this.tbxInput.Text;
            string cat = this.tbxSet.Text;
            string folder = this.tbxOutput.Text;
            string target = this.tbxTarget.Text;
            string depth = this.cbxDepth.Text;

            IStyleGalleryStorage sgs = new StyleGalleryClass();
            while (sgs.FileCount > 0)
            {
                sgs.RemoveFile(sgs.get_File(0));
            }
            IStyleGallery sg = sgs as IStyleGallery;
            sgs.AddFile(input);
            sgs.TargetFile = target;

            IPageLayout3 layout = new PageLayoutClass();
            IGraphicsContainer con = layout as IGraphicsContainer;
            IPage page = layout.Page;
            page.Units = esriUnits.esriPoints;

            IRgbColor bgc = new RgbColorClass();
            bgc.Red = 255;
            bgc.Green = 255;
            bgc.Blue = 254;
            IFrameProperties fp = page as IFrameProperties;
            ISymbolBackground bg = new SymbolBackgroundClass();
            bg.Gap = 0;
            ISimpleFillSymbol sfs = new SimpleFillSymbolClass();
            sfs.Color = bgc as IColor;
            ISimpleLineSymbol sls = new SimpleLineSymbolClass();
            sls.Style = esriSimpleLineStyle.esriSLSNull;
            sfs.Outline = sls;
            bg.FillSymbol = sfs as IFillSymbol;
            fp.Background = bg;

            IEnumStyleGalleryItem items = sg.get_Items("Marker Symbols", input, cat);
            IStyleGalleryItem item = items.Next();
            while (item != null)
            {
                //con.DeleteAllElements();
                IMarkerElement mele = new MarkerElementClass();
                IMarkerSymbol sym_m = item.Item as IMarkerSymbol;
                IMultiLayerMarkerSymbol sym_ml = sym_m as IMultiLayerMarkerSymbol;
                double pic_size;
                if (sym_ml.Size % 2 == 0)
                {
                    pic_size = sym_ml.Size+4;
                }
                else
                {
                    pic_size = sym_ml.Size+5;
                }
                page.PutCustomSize(pic_size, pic_size);
                IPoint ptn = new PointClass();
                ptn.PutCoords(pic_size / 2, pic_size / 2);
                IElement ele_i = mele as IElement;
                ele_i.Geometry = ptn;

                sym_m.Size = sym_ml.Size;
                mele.Symbol = sym_m;
                con.AddElement(ele_i, 0);
                IActiveView av = layout as IActiveView;
                string pic_file = folder+"\\"+item.Name + ".png";
                ExportPNG(av, pic_file,bgc,depth);
                con.DeleteElement(ele_i);

                ISymbol sym = CreatePictureMarkerSymbol(esriIPictureType.esriIPicturePNG, pic_file, pic_size) as ISymbol;
                IStyleGalleryItem newitem = new StyleGalleryItemClass();
                newitem.Name = item.Name;
                newitem.Item = sym;
                newitem.Category = cat;
                sg.AddItem(newitem);

                item = items.Next();
            }
            MessageBox.Show("成功导出图标");
        }