コード例 #1
0
        /// <summary>
        /// Create a BitmapType object from a BitmapImage using the factory function, and add it to the collection
        /// </summary>
        /// <param name="item"></param>
        public BitmapType AddNewItem(BitmapImage bitmap)
        {
            BitmapType item = (BitmapType)FactoryFunc(bitmap);

            AddItem(item);
            return(item);
        }
コード例 #2
0
 /// <summary>
 /// Populate the palette from a list of filenames
 /// </summary>
 /// <param name="filenames"></param>
 public void Populate(string[] filenames)
 {
     foreach (string filename in filenames)
     {
         try
         {
             Uri uri = new Uri(filename);
             if (uri.IsFile)
             {
                 FileInfo   file = new FileInfo(filename);
                 string     name = System.IO.Path.GetFileNameWithoutExtension(file.Name);
                 BitmapType item = CreateItemFromFile(name, uri);
             }
             else
             {
                 string     name = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
                 BitmapType item = CreateItemFromFile(name, uri);
             }
         }
         catch (Exception)
         {
             Console.WriteLine("Failed to load {0}", filename);
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// Add a BitmapType object to the collection
 /// </summary>
 /// <param name="item"></param>
 public void AddItem(BitmapType item, bool bCanRemove = true)
 {
     item.bCanRemove = bCanRemove;
     myItems.Add(item);
     if (null != OnItemAdded)
     {
         OnItemAdded(this, item);
     }
 }
コード例 #4
0
 /// <summary>
 /// Remove an item from the collection
 /// </summary>
 /// <param name="item"></param>
 public void RemoveItem(BitmapType item)
 {
     if (myItems.Remove(item))
     {
         if (null != OnItemRemoved)
         {
             OnItemRemoved(this, item);
         }
     }
 }
コード例 #5
0
        public BitmapType CreateItemFromResource(string name, string path)
        {
            Uri         uri   = new Uri(new Uri(@"pack://application:,,,/MyAssembly;component"), path);
            BitmapImage image = new BitmapImage(uri);
            BitmapType  x     = AddNewItem(image);

            x.Name     = name;
            x.filename = uri.AbsoluteUri;
            return(x);
        }
コード例 #6
0
        /// <summary>
        /// Create a BitmapType from a file.  Must have set the factory function to use.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="uri"></param>
        /// <returns></returns>
        public BitmapType CreateItemFromFile(string name, Uri uri)
        {
            BitmapImage image = new BitmapImage(uri);
            BitmapType  x     = AddNewItem(image);

            x.Name = name;
            if (uri.IsFile)
            {
                x.filename = Uri.UnescapeDataString(uri.AbsolutePath);
            }
            else
            {
                x.filename = uri.AbsoluteUri;
            }
            return(x);
        }