示例#1
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            if (_backgroundPath != null && _backgroundImage == null)
            {
                SetBackground(ImageGetter.LoadFromStorage(_backgroundPath, canvas.Width, canvas.Height));
            }

            if (_foregroundPath != null)
            {
                SetForeground(ImageGetter.LoadFromStorage(_foregroundPath, canvas.Width, canvas.Height));
                _foregroundPath = null;
            }
            else if (_mutableForeground == null)
            {
                SetForeground(null);
            }

            DrawBackground(canvas);

            if (_mutableForeground == null || _mutableForeground.IsRecycled)
            {
                return;
            }
            var left = (_canvasSize.Width - _mutableForeground.Width) / 2;
            var top  = (_canvasSize.Height - _mutableForeground.Height) / 2;

            canvas.DrawBitmap(_mutableForeground, (float)left, (float)top, _bitmapPaint);
            canvas.DrawPath(_currentStroke, _strokeBrush);
        }
示例#2
0
        protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
        {
            base.OnSizeChanged(w, h, oldw, oldh);
            _canvasSize = new Size(w, h);

            Bitmap foreground = null;

            try
            {
                var view = DroidFactory.MainActivity.FindViewById <ImageView>(((FragmentHistoryStack)((BaseFragment)Parent).Stack).BackgroundId);
                if (view == null)
                {
                    return;
                }
                if (_backgroundPath != null && _backgroundImage == null)
                {
                    SetBackground(ImageGetter.LoadFromStorage(_backgroundPath, view.MeasuredWidth, view.MeasuredHeight));
                }

                if (_foregroundPath != null)
                {
                    foreground = ImageGetter.LoadFromStorage(_foregroundPath, view.MeasuredWidth, view.MeasuredHeight);
                    SetForeground(null);
                    _foregroundPath = null;
                }
                else
                {
                    foreground = _mutableForeground;
                    SetForeground(Bitmap.CreateBitmap((int)_canvasSize.Width, (int)_canvasSize.Height, Bitmap.Config.Argb8888));
                    this.OnPropertyChanged("MutableForeground");
                }
            }
            catch (Exception ex)
            {
                iApp.Log.Error(ex);
            }

            if (foreground == null)
            {
                return;
            }

            var foregroundWidth  = foreground.Width;
            var foregroundHeight = foreground.Height;

            var scaled = false;

            if (foregroundWidth > _canvasSize.Width)
            {
                foregroundHeight = (int)(foregroundHeight * (_canvasSize.Width / foregroundWidth));
                foregroundWidth  = (int)_canvasSize.Width;
                scaled           = true;
            }

            if (foregroundHeight > _canvasSize.Height)
            {
                foregroundWidth  = (int)(foregroundWidth * (_canvasSize.Height / foregroundHeight));
                foregroundHeight = (int)_canvasSize.Height;
                scaled           = true;
            }

            if (scaled)
            {
                var fore = foreground;
                foreground = Bitmap.CreateScaledBitmap(foreground, foregroundWidth, foregroundHeight, false);
                fore.Recycle();
            }

            var left = foregroundWidth > _canvasSize.Width ? 0 : ((float)_canvasSize.Width - foregroundWidth) / 2;
            var top  = foregroundHeight > _canvasSize.Height ? 0 : ((float)_canvasSize.Height - foregroundHeight) / 2;

            ForegroundMutator.DrawBitmap(foreground, left, top, _bitmapPaint);
            Recycle(foreground);
        }