예제 #1
0
        protected override Bitmap Transform(IBitmapPool bitmapPool, Bitmap source, int outWidth, int outHeight)
        {
            int size = Math.Min(source.Width, source.Height);

            int width  = (source.Width - size) / 2;
            int height = (source.Height - size) / 2;

            Bitmap squaredBitmap = Bitmap.CreateBitmap(source, width, height, size, size);

            if (squaredBitmap != source)
            {
                source.Recycle();
            }

            Bitmap bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb8888);

            Canvas       canvas = new Canvas(bitmap);
            Paint        paint  = new Paint();
            BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.Clamp,
                                                   BitmapShader.TileMode.Clamp);

            paint.SetShader(shader);
            paint.AntiAlias = true;

            float r = size / 2f;

            canvas.DrawCircle(r, r, r, paint);

            squaredBitmap.Recycle();

            return(BitmapResource.Obtain(bitmap, bitmapPool).Get());
        }
예제 #2
0
        protected override Bitmap Transform(IBitmapPool bitmapPool, Bitmap source, int p2, int p3)
        {
            int size = Math.Min(source.Width, source.Height);

            int width  = (source.Width - size) / 2;
            int height = (source.Height - size) / 2;

            Bitmap bitmap = bitmapPool.Get(size, size, Bitmap.Config.Argb8888)
                            ?? Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb8888);

            Canvas       canvas = new Canvas(bitmap);
            Paint        paint  = new Paint();
            BitmapShader shader =
                new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp);

            if (width != 0 || height != 0)
            {
                // source isn't square, move viewport to center
                Matrix matrix = new Matrix();
                matrix.SetTranslate(-width, -height);
                shader.SetLocalMatrix(matrix);
            }
            paint.SetShader(shader);
            paint.AntiAlias = true;

            float r = size / 2f;

            canvas.DrawCircle(r, r, r, paint);

            return(BitmapResource.Obtain(bitmap, bitmapPool).Get());
        }
예제 #3
0
        public override Bitmap Operations(IBitmapPool bitmapPool, Bitmap source, Bitmap result)
        {
            Canvas canvas = new Canvas(result);

            Drawable mask = mContext.Resources.GetDrawable(Resource.Drawable.White_Cricle);

            mask.SetBounds(0, 0, source.Width, source.Height);
            mask.Draw(canvas);

            canvas.DrawBitmap(source, 0, 0, mMaskingPaint);

            source.Recycle();

            return(BitmapResource.Obtain(result, bitmapPool).Get());
        }