static void ImportMaki(string jsonPath, string stylePath, string renderPath, string emfPath) { IStyleGallery styleGallery = GetStyleGallery(stylePath); IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage; File.Delete(stylePath); //delete the existing Style to start from scratch styleGalleryStorage.TargetFile = stylePath; Icon[] icons = Deserialize(jsonPath); System.Array.Sort(icons); //sort by name IStyleGalleryItem2 styleGalleryItem = null; IStyleGalleryItem2 styleGalleryItemVector = null; string tags = ""; int[] sizes = {12,18,24}; int[] displays = {1,2}; //the order here is mainly to produce a pleasing experience in ArcMap. Add 96 dpi images at each size first //then add retina, finally add vector foreach (int display in displays) // do regular first, the retina { foreach (Icon icon in icons) { if (icon.tags[0] == "deprecated") { continue; } foreach (int size in sizes) { //raster version IPictureMarkerSymbol rasterPictureMarkerSymbol = MakeMarkerSymbol(renderPath,icon.icon, size, display, false); styleGalleryItem = new StyleGalleryItemClass(); styleGalleryItem.Item = rasterPictureMarkerSymbol; styleGalleryItem.Name = icon.name + " " + size + "px"; string displayDescrip = (display == 2) ? "Retina" : ""; styleGalleryItem.Category = "Picture " + displayDescrip; tags = string.Join(";", icon.tags); //make array into string styleGalleryItem.Tags = tags + ";png" + ";" + size; styleGallery.AddItem((IStyleGalleryItem)styleGalleryItem); } } } //now add vector versions to the end of the list //vector version foreach (Icon icon in icons) { if (icon.tags[0] == "deprecated"){continue;} foreach (int size in sizes) { IPictureMarkerSymbol vectorPictureMarkerSymbol = MakeMarkerSymbol(emfPath, icon.icon, size, 1, true); styleGalleryItemVector = new StyleGalleryItemClass(); styleGalleryItemVector.Item = vectorPictureMarkerSymbol; styleGalleryItemVector.Name = icon.name + " " + size + "px"; styleGalleryItemVector.Category = "Vector"; tags = string.Join(";", icon.tags); //make array into string styleGalleryItemVector.Tags = tags + ";emf" + ";" + size; styleGallery.AddItem((IStyleGalleryItem)styleGalleryItemVector); } } }
private void button1_Click(object sender, EventArgs e) { this.button1.Enabled = false; esriIPictureType ptype=esriIPictureType.esriIPicturePNG; switch (cbxPType.Text) { case "BMP": ptype=esriIPictureType.esriIPictureBitmap; break; case "GIF": ptype=esriIPictureType.esriIPictureGIF; break; case "EMF": ptype=esriIPictureType.esriIPictureEMF; break; case "JPEG": ptype=esriIPictureType.esriIPictureJPG; break; } try { int size = int.Parse(this.tbxSize.Text); string cat = this.tbxSet.Text; string folder = this.tbxFolder.Text; string target = this.tbxOutput.Text; IStyleGalleryStorage sgs = new StyleGalleryClass(); sgs.TargetFile = target; IStyleGallery sg = sgs as IStyleGallery; int i = 0; foreach (string f in Directory.GetFiles(folder)) { string name = Path.GetFileNameWithoutExtension(f); string pic = f; if (cbIsScale.Checked) { pic = ScalePicture(f, size); } ISymbol sym = CreatePictureMarkerSymbol(ptype, pic, size) as ISymbol; IStyleGalleryItem item = new StyleGalleryItemClass(); if (cbIsFileName.Checked) { item.Name = name; } else { item.Name = i.ToString(); } item.Item = sym; item.Category = cat; sg.AddItem(item); i++; } sg.SaveStyle(target, cat, ""); MessageBox.Show("�ɹ�������ʽ�⡣"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.button1.Enabled = true; }
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("成功导出图标"); }
static void ImportCSV(string csvPath, string stylePath) { //the expected field names for this util string filePath = "filePath"; string pointSize = "pointSize"; string styleItemName = "styleItemName"; string styleItemCategory = "styleItemCategory"; string styleItemTags = "styleItemTags"; IStyleGallery styleGallery = GetStyleGallery(stylePath); IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage; styleGalleryStorage.TargetFile = stylePath; ITable table = OpenCSVAsTable(csvPath); IRow row = null; int filePathIdx, styleItemNameIdx, pointSizeIdx, styleItemCategoryIdx, styleItemTagsIdx; IStyleGalleryItem3 styleGalleryItem = null; using (ComReleaser comReleaser = new ComReleaser()) { // Create the cursor. ICursor cursor = table.Search(null, false); comReleaser.ManageLifetime(cursor); filePathIdx = cursor.FindField(filePath); styleItemNameIdx = cursor.FindField(styleItemName); pointSizeIdx = cursor.FindField(pointSize); styleItemCategoryIdx = cursor.FindField(styleItemCategory); styleItemTagsIdx = cursor.FindField(styleItemTags); int rowCount = 0; while ((row = cursor.NextRow()) != null) { rowCount++; try { String itemFilePath = (string)row.get_Value(filePathIdx); IPictureMarkerSymbol pictureMarkerSymbol = MakeMarkerSymbol(itemFilePath, Convert.ToDouble(row.get_Value(pointSizeIdx))); if (pictureMarkerSymbol == null) { Console.WriteLine("Image not found: Row: " + rowCount + ", Image: " + itemFilePath); continue; } styleGalleryItem = new StyleGalleryItemClass(); styleGalleryItem.Item = pictureMarkerSymbol; styleGalleryItem.Name = row.get_Value(styleItemNameIdx) as string; styleGalleryItem.Category = row.get_Value(styleItemCategoryIdx) as string; object obj = row.get_Value(styleItemTagsIdx); // set a default tag, just in case tags field is empty string tags = styleGalleryItem.Category + ";" + styleGalleryItem.Name; // Make sure tags are set & a valid string type before converting to string if (!((obj == null) || (obj is DBNull))) tags = obj as string; const int MAX_TAG_LENGTH = 255; int tagsLength = tags.Length; if (tagsLength > MAX_TAG_LENGTH) { // WORKAROUND if length > 255 (a hard limit), trim from the front (last most important) tags = tags.Substring(tagsLength - MAX_TAG_LENGTH, MAX_TAG_LENGTH); } // Note: Tag vector symbols for later (see: containsVectorTag) // + switch to disable if desired const bool TAG_EMFS_WITH_VECTOR_TAG = true; if (TAG_EMFS_WITH_VECTOR_TAG && (itemFilePath.Substring(itemFilePath.Length - 4) == ".emf") && (!tags.ToUpper().Contains("VECTOR"))) { tags = tags + ";vector"; } styleGalleryItem.Tags = tags; //we want tags for search. If they weren't specified, use the default tags if (styleGalleryItem.Tags == "") { styleGalleryItem.Tags = styleGalleryItem.DefaultTags; } Console.WriteLine("Importing symbol " + rowCount + " : " + styleGalleryItem.Name); styleGallery.AddItem((IStyleGalleryItem)styleGalleryItem); } catch (Exception ex) { // Catch-all exception for row processing, just so 1 bad row doesn't abort the whole process Console.WriteLine("Skipping bad row: " + rowCount + ", Exception : " + ex.Message); continue; } } } }