Ejemplo n.º 1
0
        /// <summary>
        /// 转换为图标
        /// </summary>
        private Icon ToIcon(Guid categoryId, ImageInfo image)
        {
            var result = IconFactory.Create(image);

            result.CategoryId = categoryId;
            return(result);
        }
Ejemplo n.º 2
0
        private Icon CreateTransparentIcon()
        {
            graphics.Clear(Color.Black);
            TextRenderer.DrawText(graphics, GetString(), SystemFonts.StatusFont,
                                  new Point(-2, 0), Color.White, Color.Black);

            BitmapData data = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            int    stride = data.Stride;
            IntPtr Scan0  = data.Scan0;

            int numBytes = bitmap.Width * bitmap.Height * 4;

            byte[] bytes = new byte[numBytes];
            Marshal.Copy(Scan0, bytes, 0, numBytes);
            bitmap.UnlockBits(data);

            byte red, green, blue;

            for (int i = 0; i < bytes.Length; i += 4)
            {
                blue  = bytes[i];
                green = bytes[i + 1];
                red   = bytes[i + 2];

                bytes[i]     = 255;
                bytes[i + 1] = 255;
                bytes[i + 2] = 255;
                bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue);
            }

            return(IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb));
        }
Ejemplo n.º 3
0
        private Icon CreatePercentageIcon()
        {
            try
            {
                _graphics.Clear(Color.Transparent);
            }
            catch (ArgumentException)
            {
                _graphics.Clear(Color.Black);
            }
            _graphics.FillRectangle(_darkBrush, 0.5f, -0.5f, _bitmap.Width - 2, _bitmap.Height);
            float value = Sensor.Value.GetValueOrDefault();
            float y     = 0.16f * (100 - value);

            _graphics.FillRectangle(_brush, 0.5f, -0.5f + y, _bitmap.Width - 2, _bitmap.Height - y);
            _graphics.DrawRectangle(_pen, 1, 0, _bitmap.Width - 3, _bitmap.Height - 1);

            BitmapData data = _bitmap.LockBits(new Rectangle(0, 0, _bitmap.Width, _bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            byte[] bytes = new byte[_bitmap.Width * _bitmap.Height * 4];
            Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
            _bitmap.UnlockBits(data);

            return(IconFactory.Create(bytes, _bitmap.Width, _bitmap.Height, PixelFormat.Format32bppArgb));
        }
Ejemplo n.º 4
0
        private Icon CreateTransparentIcon()
        {
            string text  = GetString();
            int    count = 0;

            for (int i = 0; i < text.Length; i++)
            {
                if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-')
                {
                    count++;
                }
            }
            bool small = count > 2;

            graphics.Clear(bgColor);
            TextRenderer.DrawText(graphics, text, small ? smallFont : font,
                                  new Point(-2, small ? 1 : 0), color, bgColor);

            BitmapData data = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            IntPtr Scan0 = data.Scan0;

            int numBytes = bitmap.Width * bitmap.Height * 4;

            byte[] bytes = new byte[numBytes];
            Marshal.Copy(Scan0, bytes, 0, numBytes);
            bitmap.UnlockBits(data);

            return(IconFactory.Create(bytes, bitmap.Width, bitmap.Height,
                                      PixelFormat.Format32bppArgb));
        }
Ejemplo n.º 5
0
 /* ----------------------------------------------------------------- */
 ///
 /// DefaultIcon
 ///
 /// <summary>
 /// 既定のアイコンを取得します。
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private Icon DefaultIcon()
 {
     try { return(IconFactory.Create(StockIcons.DocumentNotAssociated, IconSize.Small)); }
     catch (Exception err)
     {
         this.LogError(err);
         return(Properties.Resources.NotAssociated);
     }
 }
Ejemplo n.º 6
0
        public void TestCreate()
        {
            const string path  = "/a/b.jpg";
            ImageInfo    image = ImageInfo.Create(path, 1, 2, 3, "c.jpg");
            var          icon  = IconFactory.Create(image);

            Assert.AreEqual(path, icon.Path);
            Assert.AreEqual("c.jpg", icon.Name);
            Assert.AreEqual(1, icon.Size);
            Assert.AreEqual(2, icon.Width);
            Assert.AreEqual(3, icon.Height);
            Assert.AreEqual(3, icon.Height);
            Assert.AreEqual("icon-b", icon.ClassName);
        }
Ejemplo n.º 7
0
        private Icon CreateTransparentIcon()
        {
            string text  = GetString();
            int    count = 0;

            for (int i = 0; i < text.Length; i++)
            {
                if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-')
                {
                    count++;
                }
            }
            bool small = count > 2;

            graphics.Clear(Color.Black);
            TextRenderer.DrawText(graphics, text, small ? smallFont : font,
                                  new Point(-2, small ? 1 : 0), Color.White, Color.Black);

            BitmapData data = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            IntPtr Scan0 = data.Scan0;

            int numBytes = bitmap.Width * bitmap.Height * 4;

            byte[] bytes = new byte[numBytes];
            Marshal.Copy(Scan0, bytes, 0, numBytes);
            bitmap.UnlockBits(data);

            byte red, green, blue;

            for (int i = 0; i < bytes.Length; i += 4)
            {
                blue  = bytes[i];
                green = bytes[i + 1];
                red   = bytes[i + 2];

                bytes[i]     = color.B;
                bytes[i + 1] = color.G;
                bytes[i + 2] = color.R;
                bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue);
            }

            return(IconFactory.Create(bytes, bitmap.Width, bitmap.Height,
                                      PixelFormat.Format32bppArgb));
        }
Ejemplo n.º 8
0
        private Icon CreatePercentageIcon()
        {
            try
            {
                _graphics.Clear(Color.Transparent);
            }
            catch (ArgumentException)
            {
                _graphics.Clear(Color.Black);
            }
            _graphics.FillRectangle(_darkBrush, 0.5f, -0.5f, _bitmap.Width - 2, _bitmap.Height);
            float value = Sensor.Value.GetValueOrDefault();
            float y     = (float)(_bitmap.Height * 0.01f) * (100 - value);

            _graphics.FillRectangle(_brush, 0.5f, -0.5f + y, _bitmap.Width - 2, _bitmap.Height - y);
            _graphics.DrawRectangle(_pen, 1, 0, _bitmap.Width - 3, _bitmap.Height - 1);

            return(IconFactory.Create(_bitmap));
        }
        private Icon CreateLoadIcon()
        {
            graphics.Clear(Color.Transparent);
            graphics.FillRectangle(darkBrush, 0.5f, -0.5f, 14, 16);
            float y = 0.16f * (100 - sensor.Value.Value);

            graphics.FillRectangle(brush, 0.5f, -0.5f + y, 14, 16 - y);
            graphics.DrawRectangle(pen, 1, 0, 13, 15);

            BitmapData data = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            byte[] bytes = new byte[bitmap.Width * bitmap.Height * 4];
            Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
            bitmap.UnlockBits(data);

            return(IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb));
        }
Ejemplo n.º 10
0
        private Icon CreateSimpleIcon()
        {
            graphics.Clear(SystemColors.ButtonFace);
            TextRenderer.DrawText(graphics, GetString(), SystemFonts.StatusFont,
                                  new Point(-2, 0), Color.Blue, SystemColors.ButtonFace);

            BitmapData data = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            int    stride = data.Stride;
            IntPtr Scan0  = data.Scan0;

            int numBytes = bitmap.Width * bitmap.Height * 4;

            byte[] bytes = new byte[numBytes];
            Marshal.Copy(Scan0, bytes, 0, numBytes);
            bitmap.UnlockBits(data);

            return(IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb));
        }
Ejemplo n.º 11
0
        private Icon CreateTransparentIcon()
        {
            string text  = GetString();
            int    count = 0;

            for (int i = 0; i < text.Length; i++)
            {
                if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-')
                {
                    count++;
                }
            }
            bool small = count > 2;

            _graphics.Clear(Color.Transparent);
            Rectangle bounds = new Rectangle(Point.Empty, _bitmap.Size);

            TextRenderer.DrawText(_graphics, text, small ? _smallFont : _font, bounds, _color, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);

            return(IconFactory.Create(_bitmap));
        }
Ejemplo n.º 12
0
        private Icon CreatePercentageIcon()
        {
            graphics.Clear(bgColor);
            //graphics.FillRectangle(bgBrush, 0, 0, bitmap.Width, bitmap.Height);

            float value = sensor.Value.GetValueOrDefault();
            float h     = bitmap.Height * value / 100.0f;

            graphics.FillRectangle(brush, 2, bitmap.Height - h - 1, bitmap.Width - 4, h);
            //graphics.DrawRectangle(pen, 1, 0, bitmap.Width - 3, bitmap.Height - 1);

            BitmapData data = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            byte[] bytes = new byte[bitmap.Width * bitmap.Height * 4];
            Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
            bitmap.UnlockBits(data);

            return(IconFactory.Create(bytes, bitmap.Width, bitmap.Height,
                                      PixelFormat.Format32bppArgb));
        }
Ejemplo n.º 13
0
 public void GetIcon_Information_Null() => Assert.That(
     IconFactory.Create(default(Cube.FileSystem.Information), IconSize.Large).Width,
     Is.EqualTo(32)
     );
Ejemplo n.º 14
0
 public void GetIcon_FileInfo_Null() => Assert.That(
     IconFactory.Create(default(System.IO.FileInfo), IconSize.Large).Width,
     Is.EqualTo(32)
     );
Ejemplo n.º 15
0
 public void GetIcon_File_NotFound() => Assert.That(
     IconFactory.Create("dummy.exe", IconSize.ExtraLarge).Width,
     Is.EqualTo(48)
     );