Пример #1
0
        public void AddMultiResBitmapTest()
        {
            var ms       = new MemoryStream();
            var refImage = Icons.Information.ToMultiResBitmap();

            using (RawIcon icon = new RawIcon())
            {
                icon.Add(refImage);
                icon.Save(ms, true);
            }

            ms.Position = 0;
            var bmp = new Bitmap(ms);

            Assert.AreEqual(ImageFormat.Icon, bmp.RawFormat);
            Assert.AreEqual(PixelFormat.Format32bppArgb, bmp.PixelFormat);
            Assert.AreEqual(OSUtils.IsWindows ? 7 : 1, bmp.ExtractIconImages().Length);
            SaveImage("result", bmp, true);
        }
Пример #2
0
        public void AddBitmapCustomBackgroundSaveUncompressedTest(string testName, PixelFormat pixelFormat, uint backColor)
        {
            var ms       = new MemoryStream();
            var size     = OSUtils.IsWindows ? new Size(256, 256) : new Size(64, 64);
            var refImage = Icons.Information.ExtractBitmap(size).ConvertPixelFormat(pixelFormat);

            using (RawIcon icon = new RawIcon())
            {
                icon.Add(refImage, Color.FromArgb((int)backColor));
                icon.Save(ms, true);
            }

            ms.Position = 0;
            var bmp = new Bitmap(ms);

            Assert.AreEqual(ImageFormat.Icon, bmp.RawFormat);
            Assert.AreEqual(PixelFormat.Format32bppArgb, bmp.PixelFormat);

            SaveImage(testName, bmp, true);
        }
Пример #3
0
        public void AddBitmapSaveUncompressedTest(PixelFormat pixelFormat)
        {
            var        ms        = new MemoryStream();
            IQuantizer quantizer = pixelFormat.IsIndexed() ? OptimizedPaletteQuantizer.Octree(1 << pixelFormat.ToBitsPerPixel()) : null;
            var        size      = OSUtils.IsWindows ? new Size(256, 256) : new Size(64, 64);
            var        refImage  = Convert(Icons.Information.ExtractBitmap(size), pixelFormat, quantizer);

            using (RawIcon icon = new RawIcon())
            {
                icon.Add(refImage);
                icon.Save(ms, true);
            }

            ms.Position = 0;
            var bmp = new Bitmap(ms);

            Assert.AreEqual(ImageFormat.Icon, bmp.RawFormat);
            Assert.AreEqual(PixelFormat.Format32bppArgb, bmp.PixelFormat);
            Assert.IsTrue(!pixelFormat.IsIndexed() && !pixelFormat.HasAlpha() || bmp.GetPixel(0, 0).A == 0, "Transparency expected");
            SaveImage($"{pixelFormat}", bmp, true);
        }
Пример #4
0
        public void AddLarge24BppBitmapTest()
        {
            var ms = new MemoryStream();

            using (var raw = new RawIcon())
            {
                raw.Add(Icons.Information.ExtractBitmap(new Size(256, 256)).ConvertPixelFormat(PixelFormat.Format24bppRgb), Color.Black);
                raw.Save(ms, false);
            }

            // <32 BPP icons are always saved uncompressed
            ms.Position = 0;

            AssertPlatformDependent(() =>
            {
                var icon = new Icon(ms);
                Assert.AreEqual(24, icon.GetBitsPerPixel());
                Assert.IsFalse(icon.IsCompressed());
                SaveIcon("result", icon);
            });
        }