public ColorPaletteSelectPage(Action <ColorPaletteSelectPage> paletteSelectCallback)
        {
            InitializeComponent();

            _paletteSelectCallback = paletteSelectCallback;

            _items = new ObservableCollection <ColorPalette>(ColorPaletteFactory.MakeAllPalettes());

            foreach (var item in _items)
            {
                SKImageInfo info   = new SKImageInfo(100, 20);
                SKBitmap    bitmap = new SKBitmap(info);
                SKCanvas    canvas = new SKCanvas(bitmap);

                var cellWidth = info.Width / item.Colors.Count;
                for (int i = 0; i < item.Colors.Count; i++)
                {
                    var paint = new SKPaint();
                    paint.Color = item.Colors[i];
                    paint.Style = SKPaintStyle.Fill;
                    canvas.DrawRect(new SKRect(i * cellWidth, 0, (i * cellWidth) + cellWidth, info.Height), paint);
                }

                var img     = SKImage.FromBitmap(bitmap);
                var encoded = img.Encode();
                item.Image = ImageSource.FromStream(encoded.AsStream);
            }

            PaletteCollection.SetBinding(CollectionView.ItemsSourceProperty, new Binding {
                Source = _items
            });
        }
예제 #2
0
        public MainPage()
        {
            InitializeComponent();

            SkiaView.PaintSurface += OnCanvasViewPaintSurface;

            SKRect bounds = new SKRect();

            _drawBitmap = new SKBitmap((int)bounds.Right,
                                       (int)bounds.Height);

            PaletteSelection.PaintSurface += OnPaletteViewPaintSurface;

            _selectedColorPalette = ColorPaletteFactory.MakeAllPalettes()[0];

            if (Device.RuntimePlatform == Device.UWP)
            {
                AppTitle.IsVisible = false;
            }
        }