Beispiel #1
0
        private void TouchUp()
        {
            var left = (_canvasSize.Width - _mutableForeground.Width) / 2;
            var top  = (_canvasSize.Height - _mutableForeground.Height) / 2;

            if (_currentStroke.IsEmpty)
            {
                _strokeBrush.SetStyle(Paint.Style.Fill);
                ForegroundMutator.DrawCircle((float)(_currentTouch.X - left), (float)(_currentTouch.Y - top), (float)StrokeThickness / 2, _strokeBrush);
            }
            else
            {
                _currentStroke.LineTo((float)_currentTouch.X, (float)_currentTouch.Y);
                // Commit the path to our offscreen canvas
                var m = new Matrix();
                m.SetTranslate((float)-left, (float)-top);
                _currentStroke.Transform(m);
                ForegroundMutator.DrawPath(_currentStroke, _strokeBrush);
            }
            // Reset the stroke so that it is not redrawn in OnDraw.
            _currentStroke.Reset();
        }
Beispiel #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);
        }