public ColorPickerView(Context context, int minWidth, int minHeight) : base(context) { SelectedColor = Color.Black.ToAndroid(); SetMinimumHeight(minHeight); SetMinimumWidth(minWidth); imageViewPallete = new ImageView(context); imageViewPallete.DrawingCacheEnabled = true; imageViewPallete.Background = new Droid.Graphics.Drawables.GradientDrawable(Droid.Graphics.Drawables.GradientDrawable.Orientation.LeftRight, COLORS); imageViewPallete.Touch += (object sender, TouchEventArgs e) => { if (e.Event.Action == MotionEventActions.Down || e.Event.Action == MotionEventActions.Move) { currentPoint = new Droid.Graphics.Point((int)e.Event.GetX(), (int)e.Event.GetY()); previewColor = GetCurrentColor(imageViewPallete.GetDrawingCache(false), (int)e.Event.GetX(), (int)e.Event.GetY()); } if (e.Event.Action == MotionEventActions.Up) { SelectedColor = previewColor; } }; imageViewSelectedColor = new ImageView(context); colorPointer = new ColorPointer(context); AddView(imageViewPallete); AddView(imageViewSelectedColor); AddView(colorPointer); }
public ColorPickerView(Context context, int minWidth, int minHeight) : base(context) { SelectedColor = Color.Black.ToAndroid(); SetMinimumHeight(minHeight); SetMinimumWidth(minWidth); imageViewPallete = new ImageView(context); imageViewPallete.Background = new Droid.Graphics.Drawables.GradientDrawable(Droid.Graphics.Drawables.GradientDrawable.Orientation.LeftRight, COLORS); imageViewPallete.Touch += (object sender, TouchEventArgs e) => { if (e.Event.Action == MotionEventActions.Down || e.Event.Action == MotionEventActions.Move) { using (Droid.Graphics.Bitmap bitmap = Droid.Graphics.Bitmap.CreateBitmap(imageViewPallete.Width, imageViewPallete.Height, Droid.Graphics.Bitmap.Config.Argb8888)) { Droid.Graphics.Canvas canvas = new Droid.Graphics.Canvas(bitmap); imageViewPallete.Background.Draw(canvas); currentPoint = new Droid.Graphics.Point((int)e.Event.GetX(), (int)e.Event.GetY()); previewColor = GetCurrentColor(bitmap, (int)e.Event.GetX(), (int)e.Event.GetY()); } } if (e.Event.Action == MotionEventActions.Up) { SelectedColor = previewColor; } }; imageViewSelectedColor = new ImageView(context); colorPointer = new ColorPointer(context); AddView(imageViewPallete); AddView(imageViewSelectedColor); AddView(colorPointer); }