Esempio n. 1
0
        /// <summary>
        /// 指定した Bitmap の色を反転します。
        /// </summary>
        /// <param name="source">反転前の画像を指定します。</param>
        /// <returns>反転後の画像を指定します。</returns>
        public static System.Drawing.Bitmap Invert(System.Drawing.Bitmap source)
        {
            System.Drawing.Bitmap    bmp  = (System.Drawing.Bitmap)source.Clone();
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);
            Imaging.BitmapData       data = bmp.LockBits(rect, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppArgb);

            System.IntPtr scan0 = data.Scan0;
            int           M     = bmp.Width * bmp.Height;

            unsafe {
                Color32Argb *p  = (Color32Argb *)(void *)scan0;
                Color32Argb *pM = p + M;
                while (p < pM)
                {
                    *p = ~*p; p++;
                }
            }
            bmp.UnlockBits(data);
            return(bmp);
        }
Esempio n. 2
0
        /// <summary>
        /// 指定した Bitmap の或る色の Pixel を全て他の色に置き換えます。
        /// </summary>
        /// <param name="bmp">変換を施す対象の Bitmap を指定します。</param>
        /// <param name="before">置き換え前の色を指定します。</param>
        /// <param name="after">置き換え後の色を指定します。</param>
        public static void ReplaceColor(System.Drawing.Bitmap bmp, Color32Argb before, Color32Argb after)
        {
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);
            Imaging.BitmapData       data = bmp.LockBits(rect, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppArgb);

            System.IntPtr scan0 = data.Scan0;
            int           M     = bmp.Width * bmp.Height;

            unsafe {
                Color32Argb *p  = (Color32Argb *)(void *)scan0;
                Color32Argb *pM = p + M;
                for (; p < pM; p++)
                {
                    if (*p == before)
                    {
                        *p = after;
                    }
                }
            }
            bmp.UnlockBits(data);
        }
Esempio n. 3
0
        /// <summary>
        /// 指定した色で指定した System.Drawing.Bitmap を塗りつぶして返します。
        /// 透明度は保持します。
        /// </summary>
        /// <param name="source">塗りつぶす前の画像を指定します。</param>
        /// <param name="color">塗り潰すのに使用する色を指定します。</param>
        /// <returns>塗り潰した結果の Bitmap を返します。</returns>
        public static System.Drawing.Bitmap ClearRGB(System.Drawing.Bitmap source, Color32Argb color)
        {
            System.Drawing.Bitmap    bmp  = (System.Drawing.Bitmap)source.Clone();
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);
            Imaging.BitmapData       data = bmp.LockBits(rect, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppArgb);

            System.IntPtr scan0 = data.Scan0;
            int           M     = bmp.Width * bmp.Height;

            unsafe {
                Color32Argb *p = (Color32Argb *)(void *)scan0;
                for (int cnt = 0; cnt < M; cnt++)
                {
                    p->R = color.R;
                    p->G = color.G;
                    p->B = color.B;
                    p++;
                }
            }
            bmp.UnlockBits(data);
            return(bmp);
        }