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


Java Shader.setLocalMatrix方法代码示例

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


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

示例1: updateDrawState

import android.graphics.Shader; //导入方法依赖的package包/类
@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(angle);
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
}
 
开发者ID:Fueled,项目名称:snippety,代码行数:11,代码来源:MultiColorSpan.java

示例2: setupPaint

import android.graphics.Shader; //导入方法依赖的package包/类
public void setupPaint(Paint paint, RectF box, float scale, float opacity) {
  float height = box.height();
  float width = box.width();
  float midX = box.centerX();
  float midY = box.centerY();
  float offsetX = (midX - width / 2);
  float offsetY = (midY - height / 2);

  int[] stopsColors = mStopColors;
  float[] stops = mStops;
  //parseGradientStops(mColors, stopsCount, stops, stopsColors, opacity);

  if (mType == GradientType.LINEAR_GRADIENT) {
    float x1 = ParserHelper.fromPercentageToFloat(mPoints.get(0), width, offsetX, scale);
    float y1 = ParserHelper.fromPercentageToFloat(mPoints.get(1), height, offsetY, scale);
    float x2 = ParserHelper.fromPercentageToFloat(mPoints.get(2), width, offsetX, scale);
    float y2 = ParserHelper.fromPercentageToFloat(mPoints.get(3), height, offsetY, scale);
    paint.setShader(
        new LinearGradient(
            x1,
            y1,
            x2,
            y2,
            stopsColors,
            stops,
            Shader.TileMode.CLAMP));
  } else {
    float rx = ParserHelper.fromPercentageToFloat(mPoints.get(2), width, 0f, scale);
    float ry = ParserHelper.fromPercentageToFloat(mPoints.get(3), height, 0f, scale);

    float cx = ParserHelper.fromPercentageToFloat(mPoints.get(4), width, offsetX, scale);
    float cy = ParserHelper.fromPercentageToFloat(mPoints.get(5), height, offsetY, scale) / (ry / rx);
    // TODO: support focus point.
    float fx = ParserHelper.fromPercentageToFloat(mPoints.get(0), width, offsetX, scale);
    float fy = ParserHelper.fromPercentageToFloat(mPoints.get(1), height, offsetY, scale) / (ry / rx);
    Shader radialGradient = new RadialGradient(
        cx,
        cy,
        rx,
        stopsColors,
        stops,
        Shader.TileMode.CLAMP
    );

    Matrix radialMatrix = new Matrix();
    radialMatrix.preScale(1f, ry / rx);
    radialGradient.setLocalMatrix(radialMatrix);
    paint.setShader(radialGradient);
  }
}
 
开发者ID:weex-plugins,项目名称:weex-svg,代码行数:51,代码来源:SvgBrush.java

示例3: doFill

import android.graphics.Shader; //导入方法依赖的package包/类
private boolean doFill(Properties atts, RectF bounding_box) {
	if ("none".equals(atts.getString("display"))) {
		return false;
	}
	if (whiteMode) {
		fillPaint.setShader(null);
		fillPaint.setColor(Color.WHITE);
		return true;
	}
	String fillString = atts.getString("fill");
          if (fillString == null && SVG_FILL != null) {
              fillString = SVG_FILL;
          }
	if (fillString != null) {
		if (fillString.startsWith("url(#")) {

			// It's a gradient fill, look it up in our map
			String id = fillString.substring("url(#".length(), fillString.length() - 1);
			Gradient g = gradientMap.get(id);
			Shader shader = null;
			if (g != null) {
				shader = g.shader;
			}
			if (shader != null) {
				// Util.debug("Found shader!");
				fillPaint.setShader(shader);
				gradMatrix.set(g.matrix);
				if (g.boundingBox && bounding_box != null) {
					// Log.d("svg", "gradient is bounding box");
					gradMatrix.preTranslate(bounding_box.left, bounding_box.top);
					gradMatrix.preScale(bounding_box.width(), bounding_box.height());
				}
				shader.setLocalMatrix(gradMatrix);
				return true;
			} else {
				Log.w(TAG, "Didn't find shader, using black: " + id);
				fillPaint.setShader(null);
				doColor(atts, Color.BLACK, true, fillPaint);
				return true;
			}
		} else if (fillString.equalsIgnoreCase("none")) {
			fillPaint.setShader(null);
			fillPaint.setColor(Color.TRANSPARENT);
			return true;
		} else {
			fillPaint.setShader(null);
                  Integer color = atts.getColor(fillString);
			if (color != null) {
				doColor(atts, color, true, fillPaint);
				return true;
			} else {
				Log.w(TAG, "Unrecognized fill color, using black: " + fillString);
				doColor(atts, Color.BLACK, true, fillPaint);
				return true;
			}
		}
	} else {
		if (fillSet) {
			// If fill is set, inherit from parent
			return fillPaint.getColor() != Color.TRANSPARENT; // optimization
		} else {
			// Default is black fill
			fillPaint.setShader(null);
			fillPaint.setColor(Color.BLACK);
			return true;
		}
	}
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:69,代码来源:SVGParser.java

示例4: doStroke

import android.graphics.Shader; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void doStroke(Path path) {
	// TODO handle degenerate subpaths properly

	if (state.style.vectorEffect == VectorEffect.NonScalingStroke) {
		// For non-scaling-stroke, the stroke width is not transformed along
		// with the path.
		// It will be rendered at the same width no matter how the document
		// contents are transformed.

		// First step: get the current canvas matrix
		Matrix currentMatrix = canvas.getMatrix();
		// Transform the path using this transform
		Path transformedPath = new Path();
		path.transform(currentMatrix, transformedPath);
		// Reset the current canvas transform completely
		canvas.setMatrix(new Matrix());

		// If there is a shader (such as a gradient), we need to update its
		// transform also
		Shader shader = state.strokePaint.getShader();
		Matrix currentShaderMatrix = new Matrix();
		if (shader != null) {
			shader.getLocalMatrix(currentShaderMatrix);
			Matrix newShaderMatrix = new Matrix(currentShaderMatrix);
			newShaderMatrix.postConcat(currentMatrix);
			shader.setLocalMatrix(newShaderMatrix);
		}

		// Render the transformed path. The stroke width used will be in
		// unscaled device units.
		canvas.drawPath(transformedPath, state.strokePaint);

		// Return the current canvas transform to what it was before all
		// this happened
		canvas.setMatrix(currentMatrix);
		// And reset the shader matrix also
		if (shader != null)
			shader.setLocalMatrix(currentShaderMatrix);
	} else {
		canvas.drawPath(path, state.strokePaint);
	}
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:44,代码来源:SVGAndroidRenderer.java


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