当前位置: 首页>>代码示例>>C#>>正文


C# Paint.SetShader方法代码示例

本文整理汇总了C#中Android.Graphics.Paint.SetShader方法的典型用法代码示例。如果您正苦于以下问题:C# Paint.SetShader方法的具体用法?C# Paint.SetShader怎么用?C# Paint.SetShader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Graphics.Paint的用法示例。


在下文中一共展示了Paint.SetShader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Transform

		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();
		}
开发者ID:thanhdatbkhn,项目名称:GlideXamarinBinding,代码行数:29,代码来源:CircleTransform.cs

示例2: Transform

        public Bitmap Transform(Bitmap source)
        {
            int size = Math.Min(source.Width, source.Height);

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

            var bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb4444);

            var canvas = new Canvas(bitmap);
            var paint = new Paint();
            var shader =
                new BitmapShader(source, BitmapShader.TileMode.Clamp, BitmapShader.TileMode.Clamp);
            if (width != 0 || height != 0)
            {
                // source isn't square, move viewport to center
                var 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);

            source.Recycle();

            return bitmap;
        }
开发者ID:nepula-h-okuyama,项目名称:DroidKaigi2016Xamarin,代码行数:30,代码来源:CropCircleTransformation.cs

示例3: ToRounded

        public static Bitmap ToRounded(Bitmap source, float rad)
        {
            int size = Math.Min(source.Width, source.Height);

            int dx = (source.Width - size) / 2;
            int dy = (source.Height - size) / 2;

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

            using (Canvas canvas = new Canvas(bitmap))
            using (Paint paint = new Paint())
            using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
            using (Matrix matrix = new Matrix())
            {
                if (dx != 0 || dy != 0)
                {
                    // source isn't square, move viewport to centre
                    matrix.SetTranslate(-dx, -dy);
                    shader.SetLocalMatrix(matrix);
                }
                paint.SetShader(shader);
                paint.AntiAlias = true;

                RectF rectF = new RectF(0, 0, size, size);
                canvas.DrawRoundRect(rectF, rad, rad, paint);

                return bitmap;
            }
        }
开发者ID:piyushdutta,项目名称:FFImageLoading,代码行数:29,代码来源:RoundedTransformation.cs

示例4: CircleDrawable

		public CircleDrawable (Bitmap bmp)
		{
			this.bmp = bmp;
			bmpShader = new BitmapShader (bmp, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
			paint = new Paint { AntiAlias = true };
			paint.SetShader (bmpShader);
			oval = new RectF ();
		}
开发者ID:richardboegli,项目名称:KinderChat,代码行数:8,代码来源:CircleDrawable.cs

示例5: Refresh

        public void Refresh()
        {
            LinkedList<DView> views = myEventHandler.GetAllView();
            Canvas c = null;
            try
            {
                if (surfaceHolder.Surface.IsValid)
                {
                    c = surfaceHolder.LockCanvas();

                    lock (surfaceHolder)
                    {
                        Paint paint = new Paint();
                        Paint paintShader = new Paint();
                        paint.Color = Color.Black;
                        c.DrawRect(0, 0
                            , this.Width, this.Height, paint);
                        foreach (var view in views)
                        {
                            if(view.ViewType==DViewType.Circle)
                            {
                                Color color=new Color(view.Pattern.Color);
                                color.A=255;
                                paint.Color = color;
                                c.DrawCircle(view.X, view.Y, view.Radius, paint);
                            }else
                            {
                                if (view.Pattern.PatternType == DPatternType.Image)
                                {
                                    BitmapShader shader = new BitmapShader(view.Pattern.Image, Shader.TileMode.Repeat, Shader.TileMode.Repeat);
                                    paintShader.SetStyle(Paint.Style.Fill);
                                    paintShader.SetShader(shader);
                                    c.DrawRect(view.X - view.Radius, view.Y - view.Radius
                                        , view.X + view.Radius, view.Y + view.Radius, paintShader);

                                }else
                                {
                                    Color color = new Color(view.Pattern.Color);
                                    color.A = 255;
                                    paint.Color = color;
                                    c.DrawRect(view.X - view.Radius, view.Y - view.Radius
                                        , view.X + view.Radius, view.Y + view.Radius, paint);
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                Log.Error("MySurfaceView",ex.Message);
            }
            finally
            {
                if (c != null)
                    surfaceHolder.UnlockCanvasAndPost(c);
            }
        }
开发者ID:mojikashani,项目名称:Switch_Media,代码行数:58,代码来源:MySurfaceView.cs

示例6: Create

		public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint)
		{
			var shader = new ag.LinearGradient(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, startColor.ToAndroid(), endColor.ToAndroid(), 
				// is this correct?
				ag.Shader.TileMode.Clamp);
			var paint = new ag.Paint();
			paint.SetShader(shader);
			return new BrushObject { Paint = paint }; // TODO: initial matrix
		}
开发者ID:mhusen,项目名称:Eto,代码行数:9,代码来源:LinearGradientBrushHandler.cs

示例7: OvalShadow

 public OvalShadow(int shadowRadius, int circleDiameter, CircleProgressBar progressBar)
     : base()
 {
     mProgressBar = progressBar;
     mShadowPaint = new Paint();
     mShadowRadius = shadowRadius;
     mCircleDiameter = circleDiameter;
     mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
         mShadowRadius, new int[] { FILL_SHADOW_COLOR, Color.Transparent },
         null, Shader.TileMode.Clamp);
     mShadowPaint.SetShader(mRadialGradient);
 }
开发者ID:devxiaruwei,项目名称:MaterialProgressbar,代码行数:12,代码来源:OvalShadow.cs

示例8: VignetteDrawable

        public VignetteDrawable(Bitmap bitmap, float cornerRadius = 5, int margin = 3, bool withEffect = true)
        {
            useGradientOverlay = withEffect;
            mCornerRadius = cornerRadius;

            bitmapShader = new BitmapShader (bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);

            paint = new Paint () { AntiAlias = true };
            paint.SetShader (bitmapShader);

            margin = margin;
        }
开发者ID:Andrea,项目名称:FriendTab,代码行数:12,代码来源:VignetteDrawable.cs

示例9: Init

		private void Init()
		{
			Drawable drawable = this.Drawable;
			bitmap = Bitmap.CreateScaledBitmap (((BitmapDrawable)drawable).Bitmap, this.Width, this.Height, false);

			BitmapShader shader;
			shader = new BitmapShader (bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);

			// init paint
			paint = new Paint ();
			paint.AntiAlias = true;
			paint.SetShader (shader);
		}
开发者ID:billy-lokal,项目名称:Dateifi_Old,代码行数:13,代码来源:RoundedImageView.cs

示例10: RoundedImage

        public RoundedImage(Bitmap bitmap)
        {
            mBitmap = bitmap;
            mRectF = new RectF();
            mPaint = new Paint();
            mPaint.AntiAlias = true;
            mPaint.Dither = true;
            BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
            mPaint.SetShader(shader);

            // NOTE: we assume bitmap is properly scaled to current density
            mBitmapWidth = mBitmap.Width;
            mBitmapHeight = mBitmap.Height;
        }
开发者ID:rrawla,项目名称:MonoDroid.UrlImageViewHelper,代码行数:14,代码来源:RoundedImage.cs

示例11: OnDraw

			protected override void OnDraw (Canvas canvas)
			{
				canvas.DrawColor (Color.White);

				Paint p = new Paint ();
				float y = 10;

				p.Color = Color.Red;
				canvas.DrawBitmap (mBitmap, 10, y, p);
				y += mBitmap.Height + 10;
				canvas.DrawBitmap (mBitmap2, 10, y, p);
				y += mBitmap2.Height + 10;
				p.SetShader (mShader);
				canvas.DrawBitmap (mBitmap3, 10, y, p);
			}
开发者ID:BratislavDimitrov,项目名称:monodroid-samples,代码行数:15,代码来源:AlphaBitmap.cs

示例12: RoundedDrawable

        public RoundedDrawable(Bitmap bitmap) : base()
        {
            mBitmap = bitmap;
            mRectF = new RectF();
            mPaint = new Paint();
            mPaint.AntiAlias = true;
            mPaint.Dither = true;

            BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
            mPaint.SetShader(shader);

            // Try to get it circular, even if the given bitmap isn't square
            mBitmapWidth = Math.Min( mBitmap.Width, mBitmap.Height);
            mBitmapHeight = Math.Min(mBitmap.Width, mBitmap.Height);
        }
开发者ID:GSDan,项目名称:Speeching_Client,代码行数:15,代码来源:RoundedDrawable.cs

示例13: DispatchDraw

        protected override void DispatchDraw(
            global::Android.Graphics.Canvas canvas)
        {
//            var gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0, 
//                               this.StartColor.ToAndroid(),
//                               this.EndColor.ToAndroid(),
//                               Android.Graphics.Shader.TileMode.Mirror);
            var gradient = new RadialGradient(-100, 1200, 3000, this.StartColor.ToAndroid(), this.EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Clamp);//(-50, -50, this.StartColor.ToAndroid(), this.EndColor.ToAndroid());
            var paint = new Android.Graphics.Paint() {
                Dither = true,
            };
            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
开发者ID:antixaker,项目名称:GradientTestApp,代码行数:15,代码来源:GradientPageRenderer.cs

示例14: Transform

        protected override Bitmap Transform(Bitmap source)
        {
            int width = source.Width;
            int height = source.Height;

            Bitmap bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.AntiAlias = true;
            paint.SetShader(new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp));
            canvas.DrawRoundRect(new RectF(margin, margin, width - margin, height - margin), radius, radius, paint);
            source.Recycle();

            return bitmap;
        }
开发者ID:dbeattie71,项目名称:FFImageLoading,代码行数:16,代码来源:RoundedCornersTransformation.cs

示例15: OnElementSizeChanged

        void OnElementSizeChanged(object sender, EventArgs e)
        {
            var elem = sender as View;
            if (elem == null)
                return;
            using (var imageBitmap = Bitmap.CreateBitmap((int)elem.Width, (int)elem.Height, Bitmap.Config.Argb8888))
            using (var canvas = new Canvas(imageBitmap))
            using (var gradient = new RadialGradient(0, 250, 1000, currentElement.StartColor.ToAndroid(), currentElement.EndColor.ToAndroid(), Shader.TileMode.Clamp))
            using (var paint = new Paint() { Dither = true })
            {
                paint.SetShader(gradient);
                canvas.DrawPaint(paint);

                Container.Background = new BitmapDrawable(imageBitmap);
            }
        }
开发者ID:antixaker,项目名称:GradientTestApp,代码行数:16,代码来源:GradientEffect.cs


注:本文中的Android.Graphics.Paint.SetShader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。