Ejemplo n.º 1
0
        private void ColorScaleVertical()
        {
            int   reso = 360;
            Color color;
            var   wb     = new WriteableBitmap(32, reso, 96, 96, PixelFormats.Pbgra32, null);
            int   h      = wb.PixelHeight;
            int   w      = wb.PixelWidth;
            int   stride = wb.BackBufferStride;

            byte[] pixels = new byte[h * stride];
            wb.CopyPixels(pixels, stride, 0);
            int p = 0;

            for (int y = 0; y < wb.PixelHeight; ++y)
            {
                color = HSV.HSV2Color(y * 360 / reso, 1f, 1f);
                for (int x = 0; x < wb.PixelWidth; ++x)
                {
                    p             = y * stride + (x * 4);
                    pixels[p + 3] = 255;
                    pixels[p + 2] = color.R;
                    pixels[p + 1] = color.G;
                    pixels[p + 0] = color.B;
                }
            }

            wb.WritePixels(new Int32Rect(0, 0, w, h), pixels, stride, 0);
            OriginBitmap   = wb;
            MyImage.Source = wb;
        }
Ejemplo n.º 2
0
        //明度が上下逆、こっちのほうが一般的みたい?
        private BitmapSource GetHueRectReverse(double hue, int size)
        {
            var wb     = new WriteableBitmap(size, size, 96, 96, PixelFormats.Pbgra32, null);
            int h      = wb.PixelHeight;
            int w      = wb.PixelWidth;
            int stride = wb.BackBufferStride;

            byte[] pixels = new byte[h * stride];
            wb.CopyPixels(pixels, stride, 0);
            int   p = 0;
            Color color;

            for (int y = 0; y < h; ++y)
            {
                for (int x = 0; x < w; ++x)
                {
                    p             = y * stride + (x * 4);
                    color         = HSV.HSV2Color(hue, (double)x / (size - 1f), 1f - ((double)y / (size - 1f)));
                    pixels[p + 3] = 255;
                    pixels[p + 2] = color.R;
                    pixels[p + 1] = color.G;
                    pixels[p + 0] = color.B;
                }
            }
            wb.WritePixels(new Int32Rect(0, 0, size, size), pixels, stride, 0);
            return(wb);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// pixelsFormats.Rgb24の色相環作成用のBitmap作成
        /// 右が赤、時計回り
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        private BitmapSource MakeHueBitmap(int size)
        {
            var wb = new WriteableBitmap(size, size, 96, 96, PixelFormats.Rgb24, null);
            //色情報用のバイト配列作成
            int stride = wb.BackBufferStride;            //横一列のバイト数、24bit = 8byteに横ピクセル数をかけた値

            byte[] pixels = new byte[size * stride * 8]; //*8はbyteをbitにするから

            //100x100のとき中心は50,50
            //ピクセル位置と画像の中心との差
            double xDiff = size / 2.0;
            double yDiff = size / 2.0;
            int    p     = 0;                  //今のピクセル位置の配列での位置

            for (int y = 0; y < size; y++)     //y座標
            {
                for (int x = 0; x < size; x++) //x座標
                {
                    //今の位置の角度を取得、これが色相になる
                    double radian = Math.Atan2(y - yDiff, x - xDiff);
                    double kakudo = Degrees(radian);
                    //色相をColorに変換
                    Color c = HSV.HSV2Color(kakudo, 1.0, 1.0);
                    //バイト配列に色情報を書き込み
                    p             = y * stride + x * 3;
                    pixels[p]     = c.R;
                    pixels[p + 1] = c.G;
                    pixels[p + 2] = c.B;
                }
            }
            //バイト配列をBitmapに書き込み
            wb.WritePixels(new Int32Rect(0, 0, size, size), pixels, stride, 0);
            return(wb);
        }
 private void ParallelImageSV(int p, int y, int stride, byte[] pixels, double hue, int w, int h)
 {
     for (int x = 0; x < w; ++x)
     {
         p = y * stride + (x * 3);
         Color svColor = HSV.HSV2Color(hue, x / (double)w, y / (double)h);
         pixels[p]     = svColor.R;
         pixels[p + 1] = svColor.G;
         pixels[p + 2] = svColor.B;
     }
 }
Ejemplo n.º 5
0
        //彩度を指定、0から1
        private BitmapSource GetSaturationRect(int width, int height, float saturation)
        {
            var wb     = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null);
            int h      = wb.PixelHeight;
            int w      = wb.PixelWidth;
            int stride = wb.BackBufferStride;

            byte[] pixels = new byte[h * stride];
            wb.CopyPixels(pixels, stride, 0);
            int   p = 0;
            Color color;

            //高さが1のときは明度を1fに固定したいので特別
            if (height == 1)
            {
                for (int x = 0; x < width; ++x)
                {
                    p     = (x * 4);
                    color = HSV.HSV2Color(
                        (x / (width - 1f)) * 359f,
                        saturation,
                        1f);
                    pixels[p + 3] = 255;
                    pixels[p + 2] = color.R;
                    pixels[p + 1] = color.G;
                    pixels[p + 0] = color.B;
                }
            }
            else
            {
                for (int y = 0; y < height; ++y)
                {
                    for (int x = 0; x < width; ++x)
                    {
                        p     = y * stride + (x * 4);
                        color = HSV.HSV2Color(
                            (x / (width - 1f)) * 359f,
                            saturation,
                            y / (double)(height - 1f));
                        pixels[p + 3] = 255;
                        pixels[p + 2] = color.R;
                        pixels[p + 1] = color.G;
                        pixels[p + 0] = color.B;
                    }
                }
            }

            wb.WritePixels(new Int32Rect(0, 0, w, h), pixels, stride, 0);
            return(wb);
        }
Ejemplo n.º 6
0
        //彩度を変化させた色相環作成
        private BitmapSource MakeHueRountRect2(int width, int height)
        {
            var wb = new WriteableBitmap(width, height, 96, 96, PixelFormats.Rgb24, null);
            //色情報用のバイト配列作成
            int stride = wb.BackBufferStride;              //横一列のバイト数、24bit = 8byteに横ピクセル数をかけた値

            byte[] pixels = new byte[height * stride * 8]; //*8はbyteをbitにするから

            //100x100のとき中心は50,50
            //ピクセル位置と画像の中心との差
            int    xDiff = width / 2;
            int    yDiff = height / 2;
            double distance;                    //中心からの距離
            double saturasion;                  //彩度
            int    p = 0;                       //今のピクセル位置の配列での位置

            for (int y = 0; y < height; y++)    //y座標
            {
                for (int x = 0; x < width; x++) //x座標
                {
                    distance   = Math.Sqrt(Math.Pow(y - yDiff, 2.0) + Math.Pow(x - xDiff, 2.0));
                    saturasion = distance / xDiff;
                    if (saturasion > 1.0)
                    {
                        saturasion = 1.0;
                    }
                    //今の位置の角度を取得、これが色相になる
                    double radian = Math.Atan2(y - yDiff, x - xDiff);
                    double kakudo = Degrees(radian);
                    //色相をColorに変換
                    Color c = HSV.HSV2Color(kakudo, saturasion, 1.0);
                    //バイト配列に色情報を書き込み
                    p             = y * stride + x * 3;
                    pixels[p]     = c.R;
                    pixels[p + 1] = c.G;
                    pixels[p + 2] = c.B;
                }
            }
            //バイト配列をBitmapに書き込み
            wb.WritePixels(new Int32Rect(0, 0, width, height), pixels, stride, 0);
            return(wb);
        }
        private BitmapSource GetImageHue(int w, int h)
        {
            var wb     = new WriteableBitmap(w, h, 96, 96, PixelFormats.Rgb24, null);
            int stride = wb.BackBufferStride;
            var pixels = new byte[h * stride];

            wb.CopyPixels(pixels, stride, 0);
            int p = 0;

            for (int y = 0; y < h; ++y)
            {
                for (int x = 0; x < w; ++x)
                {
                    p = y * stride + (x * 3);
                    Color hue = HSV.HSV2Color(y / (float)h * 360f, 1f, 1f);
                    pixels[p]     = hue.R;
                    pixels[p + 1] = hue.G;
                    pixels[p + 2] = hue.B;
                }
            }
            wb.WritePixels(new Int32Rect(0, 0, w, h), pixels, stride, 0);
            return(wb);
        }
        //HSV変更時
        private void UpDownHSV_MyValueChanged(object sender, MyValueChangedEventArgs e)
        {
            IsHsvChanging = true;
            if (IsRgbChanging != true)
            {
                IntegerUpDown.IntegerUpDown ud = (IntegerUpDown.IntegerUpDown)sender;
                if (ud == UpDownH)
                {
                    SetImageSV(UpDownH.Value);
                }

                var s = UpDownS.Value / (double)ImageSize;
                var v = UpDownV.Value / (double)ImageSize;
                Canvas.SetLeft(ThumbPicker, s * ImageSize - ThumbSize / 2f);
                Canvas.SetTop(ThumbPicker, v * ImageSize - ThumbSize / 2f);

                var col = HSV.HSV2Color(UpDownH.Value, s, v);
                R = col.R;
                G = col.G;
                B = col.B;
            }
            IsHsvChanging = false;
        }