...
Code Block | ||
---|---|---|
| ||
using HPS; using System.Drawing; using System.Collections.Generic; namespace HPSUtils { class ImageTools { public ImageTools() {} public bool AddGlyphFromImage(HPS.PortfolioKey pKey, string name, string image) { if (name != string.Empty && image != string.Empty && pKey != null) { HPS.GlyphKit glyph_kit = new GlyphKit(); List<HPS.GlyphElement> elements = new List<HPS.GlyphElement>(); HPS.DotGlyphElement pixel; Bitmap icon = new Bitmap(image); icon.RotateFlip(RotateFlipType.RotateNoneFlipY); Color clr; if (icon.Height <= 256 || icon.Width <= 256) { for (int row = 0; row < icon.Height; row++) { for (int col = 0; col < icon.Width; col++) { clr = icon.GetPixel(row, col); if (clr.A != 0) { pixel = new HPS.DotGlyphElement(); pixel.SetPoint(new GlyphPoint((sbyte)(row + 127), (sbyte)(col - 128))); pixel.SetExplicitColor(new RGBAColor(clr.R / 255f, clr.G / 255f, clr.B / 255f, clr.A / 255f)); elements.Add(pixel); } } } glyph_kit.SetElements(elements.ToArray()).SetOffset(new HPS.GlyphPoint(0, 0)).SetRadius(127); pKey.DefineGlyph(name, glyph_kit); return true; } } return false; } } } |
Additional Resources
More information can be found in our Programming Guide page on glyphs, which can be found here:https://docs.techsoft3d.com/hps/latest/build/prog_guide/0405_glyphs.htmlabout Defining And Using Glyphs.