示例#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());
        }
        private static Bitmap CircleCrop(IBitmapPool pool, Bitmap source)
        {
            if (source == null)
            {
                return(null);
            }
            var size    = Math.Min(source.Width, source.Height);
            var x       = (source.Width - size) / 2;
            var y       = (source.Height - size) / 2;
            var squared = Bitmap.CreateBitmap(source, x, y, size, size);
            var result  = pool.Get(size, size, Bitmap.Config.Argb8888);

            if (result == null)
            {
                result = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb8888);
            }

            var canvas = new Canvas(result);
            var paint  = new Paint();

            paint.SetShader(new BitmapShader(squared, Shader.TileMode.Clamp,
                                             Shader.TileMode.Clamp));
            paint.AntiAlias = true;
            var r = size / 2f;

            canvas.DrawCircle(r, r, r, paint);
            return(result);
        }
        private static Android.Graphics.Bitmap circleCrop(IBitmapPool pool, Android.Graphics.Bitmap source)
        {
            if (source == null)
            {
                return(null);
            }
            int size = Math.Min(source.Width, source.Height);
            int x    = (source.Width - size) / 2;
            int y    = (source.Height - size) / 2;

            // TO DO this could be acquired from the pool too
            Android.Graphics.Bitmap squared = Android.Graphics.Bitmap.CreateBitmap(source, x, y, size, size);
            Android.Graphics.Bitmap result  = pool.Get(size, size, Android.Graphics.Bitmap.Config.Argb8888);
            if (result == null)
            {
                result = Android.Graphics.Bitmap.CreateBitmap(size, size, Android.Graphics.Bitmap.Config.Argb8888);
            }
            Canvas canvas = new Canvas(result);
            Paint  paint  = new Paint();

            paint.SetShader(new BitmapShader(squared, BitmapShader.TileMode.Clamp,
                                             BitmapShader.TileMode.Clamp));
            paint.AntiAlias = true;
            float r = size / 2f;

            canvas.DrawCircle(r, r, r, paint);
            return(result);
        }
示例#4
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());
        }
		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();
		}
示例#6
0
        protected override Bitmap Transform(IBitmapPool bitmapPool, Bitmap source, int outWidth, int outHeight)
        {
            int width  = source.Width;
            int height = source.Height;

            int size = Math.Min(width, height);

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


            return(Operations(bitmapPool, source, result));
        }
示例#7
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());
        }
示例#8
0
        private static Android.Graphics.Bitmap roundCrop(IBitmapPool pool, Android.Graphics.Bitmap source)
        {
            if (source == null)
            {
                return(null);
            }
            Android.Graphics.Bitmap result = pool.Get(source.Width, source.Height, Android.Graphics.Bitmap.Config.Argb8888);
            if (result == null)
            {
                result = Android.Graphics.Bitmap.CreateBitmap(source.Width, source.Height, Android.Graphics.Bitmap.Config.Argb8888);
            }
            Canvas canvas = new Canvas(result);
            Paint  paint  = new Paint();

            paint.SetShader(new BitmapShader(source, BitmapShader.TileMode.Clamp, BitmapShader.TileMode.Clamp));
            paint.AntiAlias = true;
            RectF rectF = new RectF(0f, 0f, source.Width, source.Height);

            canvas.DrawRoundRect(rectF, radius, radius, paint);
            return(result);
        }
 private Bitmap CircleCrop(IBitmapPool pool, Bitmap source)
 {
     try
     {
         switch (source)
         {
         case null:
             return(null);
         }
         int    size    = (int)(Math.Min(source.Width, source.Height) - MBorderWidth / 2);
         int    x       = (source.Width - size) / 2;
         int    y       = (source.Height - size) / 2;
         Bitmap squared = Bitmap.CreateBitmap(source, x, y, size, size);
         Bitmap result  = pool.Get(size, size, Bitmap.Config.Argb8888);
         switch (result)
         {
         case null:
             result = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb8888);
             break;
         }
         //Create a brush Canvas Manually draw a border
         Canvas canvas = new Canvas(result);
         Paint  paint  = new Paint();
         paint.SetShader(new BitmapShader(squared, Shader.TileMode.Clamp, Shader.TileMode.Clamp));
         paint.AntiAlias = true;
         float r = size / 2f;
         canvas.DrawCircle(r, r, r, paint);
         if (MBorderPaint != null)
         {
             float borderRadius = r - MBorderWidth / 2;
             canvas.DrawCircle(r, r, borderRadius, MBorderPaint);
         }
         return(result);
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
         return(null);
     }
 }
        private static Bitmap RoundCrop(IBitmapPool pool, Bitmap source)
        {
            if (source == null)
            {
                return(null);
            }
            var result = pool.Get(source.Width, source.Height, Bitmap.Config.Argb8888);

            if (result == null)
            {
                result = Bitmap.CreateBitmap(source.Width, source.Height, Bitmap.Config.Argb8888);
            }

            var canvas = new Canvas(result);
            var paint  = new Paint();

            paint.SetShader(new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp));
            paint.AntiAlias = true;

            var rectF = new RectF(0f, 0f, source.Width, source.Height);

            canvas.DrawRoundRect(rectF, _radius, _radius, paint);
            return(result);
        }
 protected override Bitmap Transform(IBitmapPool pool, Bitmap toTransform,
                                     int outWidth, int outHeight)
 {
     return(RoundCrop(pool, toTransform));
 }
示例#12
0
 protected override Android.Graphics.Bitmap Transform(IBitmapPool pool, Android.Graphics.Bitmap toTransform, int outWidth, int outHeight)
 {
     return(roundCrop(pool, toTransform));
 }
示例#13
0
 public abstract Bitmap Operations(IBitmapPool bitmapPool, Bitmap source, Bitmap result);
示例#14
0
 public CropCircleTransformation(IBitmapPool p0)
     : base(p0)
 {
 }