예제 #1
0
        private async void SetColorbar(int imageID)
        {
            if (_imageID != -1)
            {
                List <Model.ImageColorInfo> lst = await SqliteUtil.Current.QueryImageColorInfoByImageID(_imageID);

                foreach (ImageColorInfo color in lst)
                {
                    BoxView box = new BoxView();
                    box.Color        = Xamarin.Forms.Color.FromHex(color.HEXValue);
                    box.CornerRadius = new CornerRadius(10);
                    pickColorList.Children.Add(box);
                }

                if (lst.Count > 0)
                {
                    ColorCode colorcd = new ColorCode();
                    string    hex     = lst[lst.Count - 1].HEXValue;
                    btnColor.BackgroundColor = Xamarin.Forms.Color.FromHex(hex);
                    lblSelected.Text         = hex;
                    lblHex.Text = hex;

                    Rgb rgb = colorcd.getRgb(hex);
                    lblRgb.Text     = colorcd.getRgbString(rgb);
                    lblHsl.Text     = colorcd.getHslString(rgb);
                    lblHsv.Text     = colorcd.getHsvString(rgb);
                    lblCmyk.Text    = colorcd.getCmykString(rgb);
                    lblLab.Text     = colorcd.getLabString(rgb);
                    lblMunsell.Text = colorcd.getMunsellString(rgb);
                    lblPccs.Text    = colorcd.getPCCSTone(rgb);
                    lblJis.Text     = JisUtil.getJisByMunsell(lblMunsell.Text);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 選択した色リストを更新する
        /// </summary>
        /// <param name="lst"></param>
        private void updatecolorBar(List <ImageColorInfo> lst, string pickColor = "")
        {
            pickColorList.Children.Clear();

            int    colorcnt    = lst.Count;
            double heightValue = pickColorList.Width / 10;

            ColorCode colorcd = new ColorCode();

            foreach (ImageColorInfo color in lst)
            {
                BoxView box = new BoxView();
                box.BackgroundColor = Xamarin.Forms.Color.FromHex(color.HEXValue);
                box.Color           = Xamarin.Forms.Color.FromHex(color.HEXValue);
                double widthHeight = pickColorList.Width / colorcnt;
                box.WidthRequest  = widthHeight;
                box.HeightRequest = heightValue;

                if (lblSelected.Text.Equals(color.HEXValue))
                {
                    box.HeightRequest = heightValue * 2;
                    box.Margin        = new Thickness(0, 0, 0, -heightValue);
                }
                var tapGestureRecognizer = new TapGestureRecognizer();
                tapGestureRecognizer.Tapped += (s, e) =>
                {
                    foreach (BoxView newBox in pickColorList.Children)
                    {
                        newBox.HeightRequest = heightValue;
                        newBox.Margin        = 0;
                    }
                    BoxView boxview = (BoxView)s;
                    boxview.HeightRequest    = heightValue * 2;
                    boxview.Margin           = new Thickness(0, 0, 0, -heightValue);
                    btnColor.BackgroundColor = boxview.Color;

                    lblSelected.Text = ToHex(boxview.BackgroundColor.ToSKColor());

                    string hex = ToHex(boxview.BackgroundColor.ToSKColor());
                    lblHex.Text = hex;
                    Rgb rgb = colorcd.getRgb(hex);
                    lblRgb.Text     = colorcd.getRgbString(rgb);
                    lblHsl.Text     = colorcd.getHslString(rgb);
                    lblHsv.Text     = colorcd.getHsvString(rgb);
                    lblCmyk.Text    = colorcd.getCmykString(rgb);
                    lblLab.Text     = colorcd.getLabString(rgb);
                    lblMunsell.Text = colorcd.getMunsellString(rgb);
                    lblPccs.Text    = colorcd.getPCCSTone(rgb);
                    lblJis.Text     = JisUtil.getJisByMunsell(lblMunsell.Text);
                };
                box.GestureRecognizers.Add(tapGestureRecognizer);

                pickColorList.Children.Add(box);
            }
        }
예제 #3
0
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            string    strHex  = lblSelected.Text;
            ColorCode colorcd = new ColorCode();

            foreach (ImageColorInfo info in qList)
            {
                if (info.HEXValue.Equals(strHex))
                {
                    qList.Remove(info);
                    break;
                }
            }
            _point    = new Xamarin.Forms.Point(0.0, 0.0);
            lastXMove = lastXMoveBak;
            lastYMove = lastYMoveBak;
            if (qList.Count > 0)
            {
                string hex = qList[qList.Count - 1].HEXValue;
                btnColor.BackgroundColor = Xamarin.Forms.Color.FromHex(hex);
                lblSelected.Text         = hex;
                lblHex.Text = hex;
                Rgb rgb = colorcd.getRgb(hex);
                lblRgb.Text     = colorcd.getRgbString(rgb);
                lblHsl.Text     = colorcd.getHslString(rgb);
                lblHsv.Text     = colorcd.getHsvString(rgb);
                lblCmyk.Text    = colorcd.getCmykString(rgb);
                lblLab.Text     = colorcd.getLabString(rgb);
                lblMunsell.Text = colorcd.getMunsellString(rgb);
                lblPccs.Text    = colorcd.getPCCSTone(rgb);
                lblJis.Text     = JisUtil.getJisByMunsell(lblMunsell.Text);
            }
            else
            {
                btnColor.BackgroundColor = Xamarin.Forms.Color.White;
                lblSelected.Text         = string.Empty;
                lblHex.Text     = string.Empty;
                lblRgb.Text     = string.Empty;
                lblHsl.Text     = string.Empty;
                lblHsv.Text     = string.Empty;
                lblCmyk.Text    = string.Empty;
                lblLab.Text     = string.Empty;
                lblMunsell.Text = string.Empty;
                lblPccs.Text    = string.Empty;
                lblJis.Text     = string.Empty;
            }

            // カンバス更新
            canvasView.InvalidateSurface();
        }
예제 #4
0
        public void reload()
        {
            ColorCode colorcd = new ColorCode();

            if (qList.Count > 0)
            {
                string hex = qList[qList.Count - 1].HEXValue;
                btnColor.BackgroundColor = Xamarin.Forms.Color.FromHex(hex);
                lblSelected.Text         = hex;
                lblHex.Text = hex;

                Rgb rgb = colorcd.getRgb(hex);
                lblRgb.Text     = colorcd.getRgbString(rgb);
                lblHsl.Text     = colorcd.getHslString(rgb);
                lblHsv.Text     = colorcd.getHsvString(rgb);
                lblCmyk.Text    = colorcd.getCmykString(rgb);
                lblLab.Text     = colorcd.getLabString(rgb);
                lblMunsell.Text = colorcd.getMunsellString(rgb);
                lblPccs.Text    = colorcd.getPCCSTone(rgb);
                lblJis.Text     = JisUtil.getJisByMunsell(lblMunsell.Text);
            }
            else
            {
                btnColor.BackgroundColor = Xamarin.Forms.Color.White;
                lblSelected.Text         = string.Empty;
                lblHex.Text     = string.Empty;
                lblRgb.Text     = string.Empty;
                lblHsl.Text     = string.Empty;
                lblHsv.Text     = string.Empty;
                lblCmyk.Text    = string.Empty;
                lblLab.Text     = string.Empty;
                lblMunsell.Text = string.Empty;
                lblPccs.Text    = string.Empty;
                lblJis.Text     = string.Empty;
            }

            // カンバス更新
            canvasView.InvalidateSurface();
        }
예제 #5
0
        /// <summary>
        /// イメージ描写
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void OnPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            if (_onCapture)
            {
                return;
            }

            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            if (bitmap.Height > bitmap.Width)
            {
                // 画像とレンズのデフォルト倍率
                scaledRatioDef = (double)bitmap.Height / (double)info.Height;

                // 画像のサーズ>レンズのサーズ
                if (scaledRatioDef > 1)
                {
                    info.Width  = (int)(info.Width * scaledRatioDef);
                    info.Height = bitmap.Height;
                }
            }
            else
            {
                // 画像とレンズのデフォルト倍率
                scaledRatioDef = (double)bitmap.Width / (double)info.Width;

                // 画像のサーズ>レンズのサーズ
                if (scaledRatioDef > 1)
                {
                    info.Height = (int)(info.Height * scaledRatioDef);
                    info.Width  = bitmap.Width;
                }
            }

            info.Width  = (int)(info.Width / scaledRatio);
            info.Height = (int)(info.Height / scaledRatio);

            if (bitmap.Width - info.Width <= 0)
            {
                defX      = (bitmap.Width - info.Width) / 2;
                lastXMove = 0;
            }
            else
            {
                defX = 0;

                if (lastXMove < 0)
                {
                    lastXMove = 0;
                }
                else if (canvasView.CanvasSize.Width + Math.Abs(lastXMove) > bitmap.Width * scaledRatio / scaledRatioDef)
                {
                    lastXMove = (bitmap.Width * scaledRatio / scaledRatioDef - canvasView.CanvasSize.Width);
                }
            }

            if (bitmap.Height - info.Height <= 0)
            {
                defY      = (bitmap.Height - info.Height) / 2;
                lastYMove = 0;
            }
            else
            {
                defY = 0;

                if (lastYMove < 0)
                {
                    lastYMove = 0;
                }
                else if (canvasView.CanvasSize.Height + Math.Abs(lastYMove) > bitmap.Height * scaledRatio / scaledRatioDef)
                {
                    lastYMove = (bitmap.Height * scaledRatio / scaledRatioDef - canvasView.CanvasSize.Height);
                }
            }

            SKRect mSrcRect  = SKRectI.Create((int)(lastXMove * scaledRatioDef / scaledRatio) + defX, (int)(lastYMove * scaledRatioDef / scaledRatio) + defY, info.Width, info.Height);
            SKRect mDestRect = SKRectI.Create(0, 0, (int)canvasView.CanvasSize.Width, (int)canvasView.CanvasSize.Height);

            canvas.Clear();
            canvas.DrawBitmap(bitmap, mSrcRect, mDestRect);

            SKPaint paint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Color       = Xamarin.Forms.Color.White.ToSKColor(),
                StrokeWidth = 5
            };

            if (_colorChanged)
            {
                using (var bmp = new SKBitmap(info))
                {
                    IntPtr    dstpixels = bmp.GetPixels();
                    ColorCode color     = new ColorCode();

                    var succeed = surface.ReadPixels(info, dstpixels, info.RowBytes,
                                                     (int)(canvasView.CanvasSize.Width * _point.X / canvasView.Width),
                                                     (int)(canvasView.CanvasSize.Height * _point.Y / canvasView.Height));

                    if (Math.Abs(defX) > 0)
                    {
                        double x = Math.Abs(defX) * canvasView.Width / (canvasView.CanvasSize.Width * scaledRatioDef);
                        if (_point.X < x || _point.X > canvasView.Width - x)
                        {
                            succeed = false;
                        }
                    }

                    if (Math.Abs(defY) > 0)
                    {
                        double y = Math.Abs(defY) * canvasView.Height / (canvasView.CanvasSize.Height * scaledRatioDef);
                        if (_point.Y < y || _point.Y > canvasView.Height - y)
                        {
                            succeed = false;
                        }
                    }

                    if (succeed)
                    {
                        if (qList.Count < 10)
                        {
                            SKColor _selectedColor = bmp.GetPixel(0, 0);
                            lblRgb.Text = RGBConverter(_selectedColor);
                            string hex = ToHex(_selectedColor);
                            lblHex.Text = hex;
                            Rgb rgb = color.getRgb(hex);
                            lblHsl.Text     = color.getHslString(rgb);
                            lblHsv.Text     = color.getHsvString(rgb);
                            lblCmyk.Text    = color.getCmykString(rgb);
                            lblLab.Text     = color.getLabString(rgb);
                            lblMunsell.Text = color.getMunsellString(rgb);
                            lblPccs.Text    = color.getPCCSTone(rgb);
                            lblJis.Text     = JisUtil.getJisByMunsell(lblMunsell.Text);

                            paint = new SKPaint
                            {
                                Style       = SKPaintStyle.Stroke,
                                Color       = Xamarin.Forms.Color.White.ToSKColor(),
                                StrokeWidth = 5
                            };
                            canvas.DrawCircle((float)(canvasView.CanvasSize.Width * _point.X / canvasView.Width),
                                              (float)(canvasView.CanvasSize.Height * _point.Y / canvasView.Height), (float)(20 * scaledRatio), paint);


                            ImageColorInfo colorinfo = new ImageColorInfo();
                            colorinfo.ImageID      = _imageID;
                            colorinfo.HEXValue     = this.lblHex.Text;
                            colorinfo.RGBValue     = this.lblRgb.Text;
                            colorinfo.HSLValue     = this.lblHsl.Text;
                            colorinfo.HSVValue     = this.lblHsv.Text;
                            colorinfo.CMYKValue    = this.lblCmyk.Text;
                            colorinfo.LABValue     = this.lblLab.Text;
                            colorinfo.MUNSELLValue = this.lblMunsell.Text;
                            colorinfo.PCCSValue    = this.lblPccs.Text;
                            colorinfo.JISValue     = this.lblJis.Text;
                            colorinfo.XValue       = (int)(_point.X);
                            colorinfo.YValue       = (int)(_point.Y);

                            colorinfo.ScaledRatio = scaledRatio;
                            colorinfo.XPis        = lastXMove;
                            colorinfo.YPis        = lastYMove;
                            colorinfo.DefX        = defX * canvasView.Width / (canvasView.CanvasSize.Width * scaledRatioDef);
                            colorinfo.DefY        = defY * canvasView.Height / (canvasView.CanvasSize.Height * scaledRatioDef);

                            qList.Add(colorinfo);

                            btnColor.BackgroundColor = Xamarin.Forms.Color.FromHex(colorinfo.HEXValue);
                            lblSelected.Text         = colorinfo.HEXValue;
                            updatecolorBar(qList, colorinfo.HEXValue);
                        }
                    }
                }
            }
            else
            {
                updatecolorBar(qList);
            }

            foreach (ImageColorInfo point in qList)
            {
                canvas.DrawCircle(
                    (float)((canvasView.CanvasSize.Width * (point.XValue + point.DefX - (defX * canvasView.Width / (canvasView.CanvasSize.Width * scaledRatioDef))) / canvasView.Width) * (scaledRatio / point.ScaledRatio) - lastXMove + (point.XPis * (scaledRatio / point.ScaledRatio))),
                    (float)((canvasView.CanvasSize.Height * (point.YValue + point.DefY - (defY * canvasView.Height / (canvasView.CanvasSize.Height * scaledRatioDef))) / canvasView.Height) * (scaledRatio / point.ScaledRatio) - lastYMove + (point.YPis * (scaledRatio / point.ScaledRatio))),
                    (float)(20 * scaledRatio), paint);
            }

            _colorChanged = false;
        }