android.graphics.Shader类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(89)

本文整理了Java中android.graphics.Shader类的一些代码示例,展示了Shader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Shader类的具体详情如下:
包路径:android.graphics.Shader
类名称:Shader

Shader介绍

暂无

代码示例

代码示例来源:origin: koral--/android-gif-drawable

@Override
  public void onDraw(Canvas canvas, Paint paint, Bitmap buffer) {
    if (mCornerRadius == 0) {
      canvas.drawBitmap(buffer, null, mDstRectF, paint);
      return;
    }
    if (mShader == null) {
      mShader = new BitmapShader(buffer, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
      final Matrix shaderMatrix = new Matrix();
      shaderMatrix.setTranslate(mDstRectF.left, mDstRectF.top);
      shaderMatrix.preScale(mDstRectF.width() / buffer.getWidth(), mDstRectF.height() / buffer.getHeight());
      mShader.setLocalMatrix(shaderMatrix);
    }
    paint.setShader(mShader);
    canvas.drawRoundRect(mDstRectF, mCornerRadius, mCornerRadius, paint);
  }
}

代码示例来源:origin: jakob-grabner/Circle-Progress-View

private void setupBarPaint() {
  if (mBarColors.length > 1) {
    mBarPaint.setShader(new SweepGradient(mCircleBounds.centerX(), mCircleBounds.centerY(), mBarColors, null));
    Matrix matrix = new Matrix();
    mBarPaint.getShader().getLocalMatrix(matrix);
    matrix.postTranslate(-mCircleBounds.centerX(), -mCircleBounds.centerY());
    matrix.postRotate(mStartAngle);
    matrix.postTranslate(mCircleBounds.centerX(), mCircleBounds.centerY());
    mBarPaint.getShader().setLocalMatrix(matrix);
    mBarPaint.setColor(mBarColors[0]);
  } else if (mBarColors.length == 1) {
    mBarPaint.setColor(mBarColors[0]);
    mBarPaint.setShader(null);
  } else {
    mBarPaint.setColor(mBarColorStandard);
    mBarPaint.setShader(null);
  }
  mBarPaint.setAntiAlias(true);
  mBarPaint.setStrokeCap(mBarStrokeCap);
  mBarPaint.setStyle(Style.STROKE);
  mBarPaint.setStrokeWidth(mBarWidth);
  if (mBarStrokeCap != Paint.Cap.BUTT) {
    mShaderlessBarPaint = new Paint(mBarPaint);
    mShaderlessBarPaint.setShader(null);
    mShaderlessBarPaint.setColor(mBarColors[0]);
  }
}

代码示例来源:origin: stackoverflow.com

@Override
public void onCreate(Bundle savedInstanceState) 
{
  super.onCreate(savedInstanceState);

  shader = new Shader(this); 

  Log.d("Fragment", "OnCreate"); 

}

代码示例来源:origin: stackoverflow.com

public static void loadAll(){
  shader1 = new Shader("com/myGame/shaders/vertex.shader", "com/myGame/shaders/fragment.shader");
  shader3 = new Shader("com/myGame/shaders/vertex3.shader", "com/myGame/shaders/fragment3.shader");
}

代码示例来源:origin: airbnb/lottie-android

@Override public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
 if (hidden) {
  return;
 }
 L.beginSection("GradientFillContent#draw");
 path.reset();
 for (int i = 0; i < paths.size(); i++) {
  path.addPath(paths.get(i).getPath(), parentMatrix);
 }
 path.computeBounds(boundsRect, false);
 Shader shader;
 if (type == GradientType.Linear) {
  shader = getLinearGradient();
 } else {
  shader = getRadialGradient();
 }
 shaderMatrix.set(parentMatrix);
 shader.setLocalMatrix(shaderMatrix);
 paint.setShader(shader);
 if (colorFilterAnimation != null) {
  paint.setColorFilter(colorFilterAnimation.getValue());
 }
 int alpha = (int) ((parentAlpha / 255f * opacityAnimation.getValue() / 100f) * 255);
 paint.setAlpha(clamp(alpha, 0, 255));
 canvas.drawPath(path, paint);
 L.endSection("GradientFillContent#draw");
}

代码示例来源:origin: com.caverock/androidsvg

Matrix  currentShaderMatrix = new Matrix();
if (shader != null) {
 shader.getLocalMatrix(currentShaderMatrix);
 Matrix  newShaderMatrix = new Matrix(currentShaderMatrix);
 newShaderMatrix.postConcat(currentMatrix);
 shader.setLocalMatrix(newShaderMatrix);
 shader.setLocalMatrix(currentShaderMatrix);

代码示例来源:origin: alexvasilkov/GestureViews

private void updateShaderMatrix() {
  if (!clipRect.isEmpty() && bitmapPaint.getShader() != null) {
    getController().getState().get(tmpMatrix);
    // Including paddings & reverting rotation (will be applied later in draw() method)
    tmpMatrix.postTranslate(getPaddingLeft(), getPaddingTop());
    tmpMatrix.postRotate(-clipRotation, clipRect.centerX(), clipRect.centerY());
    bitmapPaint.getShader().setLocalMatrix(tmpMatrix);
  }
}

代码示例来源:origin: mkulesh/microMathematics

Matrix  currentShaderMatrix = new Matrix();
if (shader != null) {
 shader.getLocalMatrix(currentShaderMatrix);
 Matrix  newShaderMatrix = new Matrix(currentShaderMatrix);
 newShaderMatrix.postConcat(currentMatrix);
 shader.setLocalMatrix(newShaderMatrix);
 shader.setLocalMatrix(currentShaderMatrix);

代码示例来源:origin: chiuki/advanced-textview

@Override
 public void updateDrawState(TextPaint paint) {
  paint.setStyle(Paint.Style.FILL);
  Shader shader = new LinearGradient(0, 0, 0, paint.getTextSize() * colors.length, colors, null,
    Shader.TileMode.MIRROR);
  Matrix matrix = new Matrix();
  matrix.setRotate(90);
  shader.setLocalMatrix(matrix);
  paint.setShader(shader);
 }
}

代码示例来源:origin: chiuki/advanced-textview

@Override
 public void updateDrawState(TextPaint paint) {
  paint.setStyle(Paint.Style.FILL);
  float width = paint.getTextSize() * colors.length;
  if (shader == null) {
   shader = new LinearGradient(0, 0, 0, width, colors, null,
     Shader.TileMode.MIRROR);
  }
  matrix.reset();
  matrix.setRotate(90);
  matrix.postTranslate(width * translateXPercentage, 0);
  shader.setLocalMatrix(matrix);
  paint.setShader(shader);
 }
}

代码示例来源:origin: zincPower/UI2018

public void init(Context context) {
  Bitmap bm = Bitmap.createBitmap(new int[]{0xFFFFFFFF, 0xFFCCCCCC, 0xFFCCCCCC, 0xFFFFFFFF},
      2, 2, Bitmap.Config.RGB_565);
  itemBackground = new BitmapShader(bm,
      Shader.TileMode.REPEAT,
      Shader.TileMode.REPEAT);
  Matrix m = new Matrix();
  m.setScale(6, 6);
  itemBackground.setLocalMatrix(m);
  mBgPaint = new Paint();
  mBitmapPaint = new Paint();
  mBitmapPaint.setAntiAlias(true);
}

代码示例来源:origin: msandroid/MultiShapeView

/**
 * 伸缩变换
 */
private void updateShaderMatrix() {
  float scale;
  float dx = 0;
  float dy = 0;
  mShaderMatrix.set(null);
  if (mBitmap.getWidth() * mRcBitmap.height() > mRcBitmap.width() * mBitmap.getHeight()) {
    scale = mRcBitmap.height() / (float) mBitmap.getHeight();
    dx = (mRcBitmap.width() - mBitmap.getWidth() * scale) * 0.5f;
  } else {
    scale = mRcBitmap.width() / (float) mBitmap.getWidth();
    dy = (mRcBitmap.height() - mBitmap.getHeight() * scale) * 0.5f;
  }
  mShaderMatrix.setScale(scale, scale);
  mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth);
  mBitmapShader.setLocalMatrix(mShaderMatrix);
}

代码示例来源:origin: wcy10586/CustomShapeImageView

private void drawShader(Canvas canvas, Bitmap bmp, float bmpW, float bmpH, float w, float h) {
  shader = new BitmapShader(bmp, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
  Matrix matrix = new Matrix();
  setMatrix(matrix, bmpW, bmpH, w, h);
  shader.setLocalMatrix(matrix);
  shaderPaint.setColor(Color.TRANSPARENT);
  shaderPaint.setShader(shader);
  canvas.drawPaint(shaderPaint);
}

代码示例来源:origin: zincPower/UI2018

private void init(Context context) {
  borderPaint = new Paint();
  borderPaint.setAntiAlias(true);
  borderPaint.setColor(Color.BLACK);
  borderPaint.setStrokeWidth(itemBorderWidth);
  textPaint = new Paint();
  textPaint.setAntiAlias(true);
  textPaint.setColor(Color.BLACK);
  textPaint.setTextSize(textSize);
  // 字体居中[即画的点为字体中间]
  textPaint.setTextAlign(Paint.Align.CENTER);
  // 图的绘制笔
  bitmapPaint = new Paint();
  bitmapPaint.setAntiAlias(true);
  Bitmap bm = Bitmap.createBitmap(new int[]{0xFFFFFFFF, 0xFFCCCCCC, 0xFFCCCCCC, 0xFFFFFFFF},
      2, 2, Bitmap.Config.RGB_565);
  itemBackground = new BitmapShader(bm,
      Shader.TileMode.REPEAT,
      Shader.TileMode.REPEAT);
  Matrix m = new Matrix();
  m.setScale(6, 6);
  itemBackground.setLocalMatrix(m);
  mRangeRectF = new RectF();
}

代码示例来源:origin: qiubiteme/android_api_demos

public SampleView(Context context) {
  super(context);
  mSrcB = makeSrc(W, H);
  mDstB = makeDst(W, H);
  // make a ckeckerboard pattern
  Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
                  0xFFCCCCCC, 0xFFFFFFFF }, 2, 2,
                  Bitmap.Config.RGB_565);
  mBG = new BitmapShader(bm,
              Shader.TileMode.REPEAT,
              Shader.TileMode.REPEAT);
  Matrix m = new Matrix();
  m.setScale(6, 6);
  mBG.setLocalMatrix(m);
}

代码示例来源:origin: zincPower/UI2018

private void init(Context context) {
  borderPaint = new Paint();
  borderPaint.setAntiAlias(true);
  borderPaint.setColor(Color.BLACK);
  borderPaint.setStrokeWidth(itemBorderWidth);
  textPaint = new Paint();
  textPaint.setAntiAlias(true);
  textPaint.setColor(Color.BLACK);
  textPaint.setTextSize(textSize);
  // 字体居中[即画的点为字体中间]
  textPaint.setTextAlign(Paint.Align.CENTER);
  // 图的绘制笔
  bitmapPaint = new Paint();
  bitmapPaint.setAntiAlias(true);
  Bitmap bm = Bitmap.createBitmap(new int[]{0xFFFFFFFF, 0xFFCCCCCC, 0xFFCCCCCC, 0xFFFFFFFF},
      2, 2, Bitmap.Config.RGB_565);
  itemBackground = new BitmapShader(bm,
      Shader.TileMode.REPEAT,
      Shader.TileMode.REPEAT);
  Matrix m = new Matrix();
  m.setScale(6, 6);
  itemBackground.setLocalMatrix(m);
}

代码示例来源:origin: stackoverflow.com

int[] rainbow = getRainbowColors();
 Shader shader = new LinearGradient(0, 0, 0, width, rainbow,
     null, Shader.TileMode.REPEAT);
 Matrix matrix = new Matrix();
 matrix.setRotate(90);
 shader.setLocalMatrix(matrix);
 mPrimaryPaint.setShader(shader);

代码示例来源:origin: THEONE10211024/ApiDemos

public SampleView(Context context) {
  super(context);
  mSrcB = makeSrc(W, H);
  mDstB = makeDst(W, H);
  // make a ckeckerboard pattern
  Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
                  0xFFCCCCCC, 0xFFFFFFFF }, 2, 2,
                  Bitmap.Config.RGB_565);
  mBG = new BitmapShader(bm,
              Shader.TileMode.REPEAT,
              Shader.TileMode.REPEAT);
  Matrix m = new Matrix();
  m.setScale(6, 6);
  mBG.setLocalMatrix(m);
}

代码示例来源:origin: EdgeJH/ArtCircleProgress

private void setProgressPaint() {
  if (!isOutMode) {
    float yStartPoint = shadowRadius + midPointY* 0.2f;
    float xStartPoint = shadowRadius + midPointX * 0.2f;
    artRect = new RectF(xStartPoint, yStartPoint, width - xStartPoint, height - yStartPoint);
  } else {
    artRect = new RectF(shadowRadius*1.5f, shadowRadius*1.5f, width-shadowRadius*1.5f , height - shadowRadius*1.5f);
  }
  gradient = new SweepGradient(midPointX, midPointY, progressStartColor, progressEndColor);
  Matrix gradientMatrix = new Matrix();
  gradientMatrix.preRotate(90f, midPointX, midPointY);
  gradient.setLocalMatrix(gradientMatrix);
  progressPaint = new Paint();
  progressPaint.setShader(gradient);
  progressPaint.setAntiAlias(true);
  progressPaint.setStrokeCap(Paint.Cap.ROUND);
  progressPaint.setStyle(Paint.Style.STROKE);
  progressPaint.setStrokeWidth(progressWidth);
  progressPaint.setColor(Color.BLACK);
}

代码示例来源:origin: derry/delion

mShadowMatrix.postRotate(180);
mShadowMatrix.postTranslate(left, bottom);
mShadowShader.setLocalMatrix(mShadowMatrix);
mShadowPaint.setShader(mShadowShader);
canvas.drawRect(left, bottom - scaledShadowHeight, right, bottom, mShadowPaint);
mShadowMatrix.setScale(1, scaledShadowHeight);
mShadowMatrix.postTranslate(left, top);
mShadowShader.setLocalMatrix(mShadowMatrix);
mShadowPaint.setShader(mShadowShader);
canvas.drawRect(left, top, right, top + scaledShadowHeight, mShadowPaint);

相关文章