Example #1
0
        public void FileIcon(uint id, RectangleF rect, string path)
        {
            var systemIcon = SystemIcon.Get(path, true);

            //throw new NotImplementedException();
            if (systemIcon.ImageList == IntPtr.Zero)
            {
                return;
            }

            int w = 0;
            int h = 0;

            if (!Comctl32.ImageList_GetIconSize(systemIcon.ImageList, ref w, ref h))
            {
                return;
            }

            Bitmap bitmap;

            if (!m_imageListMap.TryGetValue(systemIcon.ImageListIndex, out bitmap))
            {
                using (var memoryBitmap = new MemoryBitmap(w, h))
                {
                    Comctl32.ImageList_Draw(systemIcon.ImageList, systemIcon.ImageListIndex,
                                            memoryBitmap.DC, 0, 0, ILD.NORMAL);

                    var bytes = memoryBitmap.GetBitmap();
                    if (bytes != null)
                    {
                        using (var s = new DataStream(w * h * 4, true, true))
                        {
                            s.Write(bytes, 0, bytes.Length);
                            s.Position = 0;
                            bitmap     = new Bitmap(m_device.D2DDeviceContext, new Size2(w, h), s, w * 4, GetBP);
                            m_imageListMap.Add(systemIcon.ImageListIndex, bitmap);
                        }
                    }
                }
            }

            //m_device.D2DDeviceContext.DrawBitmap(bitmap, new RectangleF(rect.X, rect.Y, w, h), 1.0f, BitmapInterpolationMode.Linear);
        }