コード例 #1
0
        public void ColorToOpaquePbgra32()
        {
            Assert.AreEqual(0xFF203040, BitmapUtility.ColorToOpaquePbgra32(
                                Color.FromArgb(0xFF, 0x20, 0x30, 0x40)));

            Assert.AreEqual(0xFF203040, BitmapUtility.ColorToOpaquePbgra32(
                                Color.FromArgb(0x7F, 0x20, 0x30, 0x40)));

            Assert.AreEqual(0xFF203040, BitmapUtility.ColorToOpaquePbgra32(
                                Color.FromArgb(0x00, 0x20, 0x30, 0x40)));
        }
コード例 #2
0
ファイル: BitmapBuffer.cs プロジェクト: prepare/Tektosyne.NET
        /// <summary>
        /// Makes the specified <see cref="Color"/> transparent in the <see cref="BitmapBuffer"/>.
        /// </summary>
        /// <param name="color">
        /// The <see cref="Color"/> to replace with transparent black.</param>
        /// <remarks><para>
        /// <b>MakeTransparent</b> sets all fully opaque <see cref="Pixels"/> of the specified
        /// <paramref name="color"/> to zero, which is the <see cref="PixelFormats.Pbgra32"/>
        /// equivalent of transparent black color. Partially transparent <see cref="Pixels"/> and
        /// <see cref="Pixels"/> of any other color remain unchanged.
        /// </para><para>
        /// <b>MakeTransparent</b> ignores the alpha channel of the specified <paramref
        /// name="color"/> and only replaces fully opaque <see cref="Pixels"/> because the
        /// imprecision caused by the premultiplication of color channels in the <see
        /// cref="PixelFormats.Pbgra32"/> format would otherwise produce false matches.
        /// </para><note type="implementnotes">
        /// The predefined <see cref="Colors.Transparent"/> color is transparent <em>white</em> (all
        /// color channels maximized), not transparent <em>black</em> (all color channels zero).
        /// That color is not representable in <see cref="PixelFormats.Pbgra32"/> format since all
        /// color channel information of fully transparent color is lost.</note></remarks>

        public void MakeTransparent(Color color)
        {
            uint value = BitmapUtility.ColorToOpaquePbgra32(color);

            for (int i = 0; i < _pixels.Length; i++)
            {
                if (_pixels[i] == value)
                {
                    _pixels[i] = 0u;
                }
            }
        }