读取devexpress 封装好的图标

public static class DXImageGalleryLoader

        {

            public static DevExpress.XtraBars.Ribbon.GalleryItemCollection Load()

            {

                DevExpress.XtraBars.Ribbon.GalleryItemCollection dataModel = new DevExpress.XtraBars.Ribbon.GalleryItemCollection();

                using (System.Resources.ResourceReader reader = GetResourceReader(DevExpress.Utils.DxImageAssemblyUtil.ImageAssembly))

                {

                    System.Collections.IDictionaryEnumerator dict = reader.GetEnumerator();

                    while (dict.MoveNext())

                    {

                        string key = (string)dict.Key as string;

                        if (!DevExpress.Utils.DxImageAssemblyUtil.ImageProvider.IsBrowsable(key)) continue;

                        if (IsImageBasedResource(key))

                        {

                            Image image = GetImageFromStream((System.IO.Stream)dict.Value);

                            if (image != null)

                                dataModel.Add(new DevExpress.XtraBars.Ribbon.GalleryItem(image, image.ToString(), key));

                        }

                    }

                }

                return dataModel;

            }



            static bool IsImageBasedResource(string key)

            {

                return key.EndsWith(".png", StringComparison.Ordinal);

            }

            static System.Resources.ResourceReader GetResourceReader(System.Reflection.Assembly imagesAssembly)

            {

                var resources = imagesAssembly.GetManifestResourceNames();

                var imageResources = Array.FindAll(resources, resourceName => resourceName.EndsWith(".resources"));

                if (imageResources.Length != 1)

                {

                    throw new Exception("读取异常");

                }

                return new System.Resources.ResourceReader(imagesAssembly.GetManifestResourceStream(imageResources[0]));

            }

            static Image GetImageFromStream(System.IO.Stream stream)

            {

                Image res = null;

                try

                {

                    res = Image.FromStream(stream);

                }

                catch { res = null; }

                return res;

            }

  /// <summary>

        /// 初始化galleryControl

        /// </summary>

        void InitGallery()

        {

            galleryControl1.Gallery.Groups.Clear();

            GalleryItemGroup group = new GalleryItemGroup() { Caption = "Custom" };

            galleryControl1.Gallery.Groups.Add(group);

            group.Items.AddRange(DXImageGalleryLoader.Load().Take(1000).ToArray());

        }

        }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值