Example #1
0
        public object Clone()
        {
            TocClass clone = (TocClass)this.MemberwiseClone();

            if (Image != null)
            {
                clone.Image = new byte[Image.Length];
                Image.CopyTo(clone.Image, 0);
            }

            return(clone);
        }
Example #2
0
        public static TocClass ReadFrom(ArcXmlReader reader)
        {
            try
            {
                TocClass tocClass = new TocClass();

                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        string value = reader.ReadContentAsString();

                        if (value.Length > 0)
                        {
                            switch (reader.Name)
                            {
                            case "description": tocClass.Description = value; break;

                            case "label": tocClass.Label = value; break;
                            }
                        }
                    }

                    reader.MoveToElement();
                }

                if (!reader.IsEmptyElement)
                {
                    string imageData = reader.ReadString();
                    tocClass.Image = Convert.FromBase64String(imageData);

                    Bitmap bitmap = new Bitmap(new MemoryStream(tocClass.Image));
                    tocClass.ImageIsTransparent = true;

                    for (int row = 0; row < bitmap.Width; ++row)
                    {
                        for (int col = 0; col < bitmap.Height; ++col)
                        {
                            if (bitmap.GetPixel(row, col).A > 0)
                            {
                                tocClass.ImageIsTransparent = false;
                                break;
                            }
                        }

                        if (!tocClass.ImageIsTransparent)
                        {
                            break;
                        }
                    }
                }

                return(tocClass);
            }
            catch (Exception ex)
            {
                if (ex is ArcXmlException)
                {
                    throw ex;
                }
                else
                {
                    throw new ArcXmlException(String.Format("Could not read {0} element.", XmlName), ex);
                }
            }
        }