Exemplo n.º 1
0
        public static Bitmap AddShadow(Bitmap bm, int dstHeight, int dstWidth)
        {
            var color = Color.Black;
            int size  = 7;
            int dx    = 2;
            int dy    = 5;

            var mask = Bitmap.CreateBitmap(dstWidth, dstHeight, Bitmap.Config.Alpha8);

            Matrix scaleToFit = new Matrix();
            RectF  src        = new RectF(0, 0, bm.Width, bm.Height);
            RectF  dst        = new RectF(0, 0, dstWidth - dx, dstHeight - dy);

            scaleToFit.SetRectToRect(src, dst, Matrix.ScaleToFit.Center);

            Matrix dropShadow = new Matrix(scaleToFit);

            dropShadow.PostTranslate(dx, dy);

            Canvas maskCanvas = new Canvas(mask);
            Paint  paint      = new Paint(PaintFlags.AntiAlias);

            maskCanvas.DrawBitmap(bm, scaleToFit, paint);
            paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcOut));
            maskCanvas.DrawBitmap(bm, dropShadow, paint);

            var filter = new BlurMaskFilter(size, BlurMaskFilter.Blur.Normal);

            paint.Reset();
            paint.AntiAlias = true;
            paint.Color     = color;
            paint.SetMaskFilter(filter);
            paint.FilterBitmap = true;

            var ret       = Bitmap.CreateBitmap(dstWidth, dstHeight, Bitmap.Config.Argb8888);
            var retCanvas = new Canvas(ret);

            retCanvas.DrawBitmap(mask, 0, 0, paint);
            retCanvas.DrawBitmap(bm, scaleToFit, null);
            mask.Recycle();
            return(ret);
        }
Exemplo n.º 2
0
        private void DrawBrush(float x, float y)
        {
            // get vector from previous to current position
            float xdist = x - _PreviousX;
            float ydist = y - _PreviousY;

            // get the length
            float segmentLength = (float)Math.Sqrt(xdist * xdist + ydist * ydist);

            // derive a suitable step size from stroke width
            float stepSize = Math.Max((float)(ToolManager.Instance.BrushSize / 10), 1f);

            // calculate the number of steps we need to take
            // NOTE: this draws a bunch of evenly spaced splashes from the start point
            // to JUST BEFORE the end point. The end point will be drawn by the start point of the
            // next stroke, or by the touch_up method. If we drew both the start and
            // end point there it would be doubled up
            int steps = (int)Math.Max(Math.Round((double)(segmentLength / stepSize)), 2);

            Bitmap b = ScaleBitmap(BrushBitmap, (int)ToolManager.Instance.BrushSize, (int)ToolManager.Instance.BrushSize);
            Paint  p = new Paint();

            p.Alpha     = ToolManager.Instance.Alpha;
            p.AntiAlias = ToolManager.Instance.AntiAlias;
            p.SetColorFilter(new LightingColorFilter(Color.ParseColor("#" + ToolManager.Instance.ForegroundColor), 0));
            BlurMaskFilter filter = new BlurMaskFilter((float)ToolManager.Instance.BlurRadius, BlurMaskFilter.Blur.Normal);

            p.SetMaskFilter(filter);

            for (int i = 0; i < steps; i++)
            {
                int currentX = (int)(_PreviousX + xdist * i / steps);
                int currentY = (int)(_PreviousY + ydist * i / steps);
                DrawCanvas.DrawBitmap(b, x - (int)ToolManager.Instance.BrushSize / 2, y - (int)ToolManager.Instance.BrushSize / 2, p);
            }

            // update the previous position
            _PreviousX = x;
            _PreviousY = y;
        }
Exemplo n.º 3
0
        protected override void onDraw(Canvas canvas)
        {
            canvas.drawColor(unchecked ((int)0xFFDDDDDD));

            canvas.save();

            Paint paint = new Paint();

            paint.setColor(Color.BLUE);

            MaskFilter mf = new BlurMaskFilter(128, BlurMaskFilter.Blur.NORMAL);

            paint.setMaskFilter(mf);
            mf.Dispose();

            canvas.translate(200, 200);
            canvas.drawCircle(100, 100, 200, paint);

            canvas.restore();

            paint.Dispose();
        }
        void Initialize()
        {
            window_manager = (Context.GetSystemService(Context.WindowService)).JavaCast <IWindowManager> ();

            //set background paint properties
            background_paint = new Paint();
            background_paint.SetStyle(Paint.Style.Fill);
            background_paint.Dither    = true;
            background_paint.AntiAlias = true;

            image_paint = new Paint();

            //set properties for the other paints
            circle_paint = new Paint();
            circle_paint.SetStyle(Paint.Style.Fill);
            circle_paint.Dither    = true;
            circle_paint.AntiAlias = true;

            led_paint = new Paint();
            led_paint.SetStyle(Paint.Style.Fill);
            led_paint.Dither    = true;
            led_paint.AntiAlias = true;
            BlurMaskFilter blur_mask_filter = new BlurMaskFilter(20.0f, BlurMaskFilter.Blur.Outer);

            led_paint.SetMaskFilter(blur_mask_filter);

            directional_paint           = new Paint();
            directional_paint.Dither    = true;
            directional_paint.AntiAlias = true;
            directional_paint.Alpha     = 204;

            gradient_paint           = new Paint();
            gradient_paint.Dither    = true;
            gradient_paint.AntiAlias = true;
            gradient_paint.Alpha     = 204;
        }
Exemplo n.º 5
0
        public SVGFilterElementGaussianBlur(float pStandardDeviation)
        {
            float radius = pStandardDeviation * 2;

            this.mBlurMaskFilter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.Normal);
        }