本文整理汇总了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();
}
示例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;
}
示例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;
}
}
示例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 ();
}
示例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);
}
}
示例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
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}