本文整理汇总了Java中android.graphics.Path.transform方法的典型用法代码示例。如果您正苦于以下问题:Java Path.transform方法的具体用法?Java Path.transform怎么用?Java Path.transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Path
的用法示例。
在下文中一共展示了Path.transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotatedOval
import android.graphics.Path; //导入方法依赖的package包/类
private Bitmap rotatedOval(Bitmap bitmap) {
Bitmap bmp;
float width = bitmap.getWidth();
float height = bitmap.getHeight();
bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Path oval = new Path();
Matrix matrix = new Matrix();
RectF ovalRect = new RectF(width / OVAL_FACTOR, 0, width - (width / OVAL_FACTOR), height);
oval.addOval(ovalRect, Path.Direction.CW);
matrix.postRotate(ROTATION, width / 2, height / 2);
oval.transform(matrix, oval);
canvas.drawPath(oval, paint);
return bmp;
}
示例2: render
import android.graphics.Path; //导入方法依赖的package包/类
public void render(Canvas canvas) {
if (this.canvas == null) return;
float scaleX = 1.0F * canvas.getWidth() / this.canvas.getWidth();
float scaleY = 1.0F * canvas.getHeight() / this.canvas.getHeight();
Matrix matrix = new Matrix();
matrix.setScale(scaleX, scaleY);
for (int i = 0; i < this.historyPointer; i++) {
Path path = this.pathLists.get(i);
Paint paint = this.paintLists.get(i);
Path scaledPath = new Path();
path.transform(matrix, scaledPath);
Paint scaledPaint = new Paint(paint);
scaledPaint.setStrokeWidth(scaledPaint.getStrokeWidth() * scaleX);
canvas.drawPath(scaledPath, scaledPaint);
}
}
示例3: computePath
import android.graphics.Path; //导入方法依赖的package包/类
private void computePath(Rect bounds) {
final float currentScale = mCurrentScale;
final Path path = mPath;
final RectF rect = mRect;
final Matrix matrix = mMatrix;
path.reset();
int totalSize = Math.min(bounds.width(), bounds.height());
float initial = mClosedStateSize;
float destination = totalSize;
float currentSize = initial + (destination - initial) * currentScale;
float halfSize = currentSize / 2f;
float inverseScale = 1f - currentScale;
float cornerSize = halfSize * inverseScale;
float[] corners = new float[]{halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize};
rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
path.addRoundRect(rect, corners, Path.Direction.CCW);
matrix.reset();
matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
matrix.postTranslate(0, hDiff);
path.transform(matrix);
}
示例4: computePath
import android.graphics.Path; //导入方法依赖的package包/类
private void computePath(Rect bounds) {
final float currentScale = mCurrentScale;
final Path path = mPath;
final RectF rect = mRect;
final Matrix matrix = mMatrix;
path.reset();
int totalSize = Math.min(bounds.width(), bounds.height());
float initial = mClosedStateSize;
float currentSize = initial + ((float) totalSize - initial) * currentScale;
float halfSize = currentSize / 2f;
float inverseScale = 1f - currentScale;
float cornerSize = halfSize * inverseScale;
float[] corners = new float[]{halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize};
rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
path.addRoundRect(rect, corners, Path.Direction.CCW);
matrix.reset();
matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
matrix.postTranslate(0, hDiff);
path.transform(matrix);
}
示例5: drawIndicator
import android.graphics.Path; //导入方法依赖的package包/类
private void drawIndicator() {
float xPos = x + (getNearestDeviation() * gaugeWidth / MAX_DEVIATION);
float yPosition = y * 1.15f;
Matrix matrix = new Matrix();
float scalingFactor = numbersPaint.getTextSize() / 3;
matrix.setScale(scalingFactor, scalingFactor);
Path indicator = new Path();
indicator.moveTo(0, -2);
indicator.lineTo(1, 0);
indicator.lineTo(-1, 0);
indicator.close();
indicator.transform(matrix);
indicator.offset(xPos, yPosition);
canvas.drawPath(indicator, gaugePaint);
}
示例6: clippedRotatedOval
import android.graphics.Path; //导入方法依赖的package包/类
private Bitmap clippedRotatedOval(Bitmap bitmap) {
Bitmap bmp;
float width = bitmap.getWidth();
float height = bitmap.getHeight();
bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Path oval = new Path();
Matrix matrix = new Matrix();
Region region = new Region();
RectF ovalRect = new RectF(width / OVAL_FACTOR, 0, width - (width / OVAL_FACTOR), height);
oval.addOval(ovalRect, Path.Direction.CW);
matrix.postRotate(ROTATION, width / 2, height / 2);
oval.transform(matrix, oval);
region.setPath(oval, new Region((int) width / 2, 0, (int) width, (int) height));
canvas.drawPath(region.getBoundaryPath(), paint);
return bmp;
}
示例7: pathValueToPixel
import android.graphics.Path; //导入方法依赖的package包/类
/**
* transform a path with all the given matrices VERY IMPORTANT: keep order
* to value-touch-offset
*
* @param path
*/
public void pathValueToPixel(Path path) {
path.transform(mMatrixValueToPx);
path.transform(mViewPortHandler.getMatrixTouch());
path.transform(mMatrixOffset);
}
示例8: isShape
import android.graphics.Path; //导入方法依赖的package包/类
/**
* Returns if the shape of the icon is same as the path.
* For this method to work, the shape path bounds should be in [0,1]x[0,1] bounds.
*/
private boolean isShape(Path maskPath) {
// Condition1:
// If width and height of the path not close to a square, then the icon shape is
// not same as the mask shape.
float iconRatio = ((float) mBounds.width()) / mBounds.height();
if (Math.abs(iconRatio - 1) > BOUND_RATIO_MARGIN) {
return false;
}
// Condition 2:
// Actual icon (white) and the fitted shape (e.g., circle)(red) XOR operation
// should generate transparent image, if the actual icon is equivalent to the shape.
mFileId = mRandom.nextInt();
mBitmapARGB.eraseColor(Color.TRANSPARENT);
mCanvasARGB.drawBitmap(mBitmap, 0, 0, mPaintIcon);
// Fit the shape within the icon's bounding box
mMatrix.reset();
mMatrix.setScale(mBounds.width(), mBounds.height());
mMatrix.postTranslate(mBounds.left, mBounds.top);
maskPath.transform(mMatrix);
// XOR operation
mCanvasARGB.drawPath(maskPath, mPaintMaskShape);
// DST_OUT operation around the mask path outline
mCanvasARGB.drawPath(maskPath, mPaintMaskShapeOutline);
boolean isTrans = isTransparentBitmap(mBitmapARGB);
// Check if the result is almost transparent
if (!isTrans) {
return false;
}
return true;
}
示例9: calcPath
import android.graphics.Path; //导入方法依赖的package包/类
private static void calcPath(Path path, float[] ys, Matrix m) {
path.reset();
int xs = ys.length;
for (int x = 0; x < xs; x++) {
if (x == 0) {
path.moveTo(x / (float) (xs - 1), 1 - ys[x]);
continue;
}
path.lineTo(x / (float) (xs - 1), 1 - ys[x]);
}
path.transform(m);
}
示例10: getScaledPath
import android.graphics.Path; //导入方法依赖的package包/类
private Path getScaledPath(Path origPath, Rect origRect, int width, int height) {
Rect newRect = new Rect(0, 0, width, height);
int origWidth = origRect.right - origRect.left;
int origHeight = origRect.bottom - origRect.top;
Matrix matrix = new Matrix();
matrix.postScale((float) (newRect.right - newRect.left) / origWidth, (float) (newRect.bottom - newRect.top) / origHeight);
Path newPath = new Path();
origPath.transform(matrix, newPath);
return newPath;
}
示例11: heart
import android.graphics.Path; //导入方法依赖的package包/类
private Bitmap heart(Bitmap bitmap) {
Bitmap bmp;
float width = bitmap.getWidth();
float height = bitmap.getHeight();
bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Path oval = new Path();
Matrix matrix = new Matrix();
Region region = new Region();
RectF ovalRect = new RectF(width / OVAL_FACTOR, 0, width - (width / OVAL_FACTOR), height);
oval.addOval(ovalRect, Path.Direction.CW);
matrix.postRotate(ROTATION, width / 2, height / 2);
oval.transform(matrix, oval);
region.setPath(oval, new Region((int) width / 2, 0, (int) width, (int) height));
canvas.drawPath(region.getBoundaryPath(), paint);
matrix.reset();
oval.reset();
oval.addOval(ovalRect, Path.Direction.CW);
matrix.postRotate(-ROTATION, width / 2, height / 2);
oval.transform(matrix, oval);
region.setPath(oval, new Region(0, 0, (int) width / 2, (int) height));
canvas.drawPath(region.getBoundaryPath(), paint);
return bmp;
}
示例12: drawArc
import android.graphics.Path; //导入方法依赖的package包/类
public static void drawArc(Path p, float lastX, float lastY, float x, float y, float rx, float
ry, float theta, int largeArc, int sweepArc) {
Log.d("drawArc", "from (" + lastX + "," + lastY + ") to (" + x + "," + y + ") r=(" + rx + "," + ry +
") theta=" + theta + " flags=" + largeArc + "," + sweepArc);
// http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
if (rx == 0 || ry == 0) {
p.lineTo(x, y);
return;
}
if (x == lastX && y == lastY) {
return; // nothing to draw
}
rx = Math.abs(rx);
ry = Math.abs(ry);
final float thrad = theta * (float) Math.PI / 180;
final float st = (float) Math.sin(thrad);
final float ct = (float) Math.cos(thrad);
final float xc = (lastX - x) / 2;
final float yc = (lastY - y) / 2;
final float x1t = ct * xc + st * yc;
final float y1t = -st * xc + ct * yc;
final float x1ts = x1t * x1t;
final float y1ts = y1t * y1t;
float rxs = rx * rx;
float rys = ry * ry;
float lambda = (x1ts / rxs + y1ts / rys) * 1.001f; // add 0.1% to be sure that no out of range occurs due to
// limited precision
if (lambda > 1) {
float lambdasr = (float) Math.sqrt(lambda);
rx *= lambdasr;
ry *= lambdasr;
rxs = rx * rx;
rys = ry * ry;
}
final float R =
(float) Math.sqrt((rxs * rys - rxs * y1ts - rys * x1ts) / (rxs * y1ts + rys * x1ts))
* ((largeArc == sweepArc) ? -1 : 1);
final float cxt = R * rx * y1t / ry;
final float cyt = -R * ry * x1t / rx;
final float cx = ct * cxt - st * cyt + (lastX + x) / 2;
final float cy = st * cxt + ct * cyt + (lastY + y) / 2;
final float th1 = angle(1, 0, (x1t - cxt) / rx, (y1t - cyt) / ry);
float dth = angle((x1t - cxt) / rx, (y1t - cyt) / ry, (-x1t - cxt) / rx, (-y1t - cyt) / ry);
if (sweepArc == 0 && dth > 0) {
dth -= 360;
} else if (sweepArc != 0 && dth < 0) {
dth += 360;
}
// draw
if ((theta % 360) == 0) {
// no rotate and translate need
arcRectf.set(cx - rx, cy - ry, cx + rx, cy + ry);
p.arcTo(arcRectf, th1, dth);
} else {
// this is the hard and slow part :-)
arcRectf.set(-rx, -ry, rx, ry);
arcMatrix.reset();
arcMatrix.postRotate(theta);
arcMatrix.postTranslate(cx, cy);
arcMatrix.invert(arcMatrix2);
p.transform(arcMatrix2);
p.arcTo(arcRectf, th1, dth);
p.transform(arcMatrix);
}
}
示例13: transform
import android.graphics.Path; //导入方法依赖的package包/类
public void transform(Matrix matrix) {
path = new Path(originalPath);
path.transform(matrix);
}
示例14: getScaledAndOffsetPath
import android.graphics.Path; //导入方法依赖的package包/类
public Path getScaledAndOffsetPath(float offsetX, float offsetY, float scaleX, float scaleY) {
Path newPath = new Path(path);
newPath.offset(offsetX, offsetY);
newPath.transform(getScaleMatrix(newPath, scaleX, scaleY));
return newPath;
}
示例15: drawArc
import android.graphics.Path; //导入方法依赖的package包/类
private static void drawArc(Path p, float lastX, float lastY, float x, float y, float rx, float ry, float theta,
int largeArc, int sweepArc) {
// Log.d("drawArc", "from (" + lastX + "," + lastY + ") to (" + x + ","+ y + ") r=(" + rx + "," + ry +
// ") theta=" + theta + " flags="+ largeArc + "," + sweepArc);
// http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
if (rx == 0 || ry == 0) {
p.lineTo(x, y);
return;
}
if (x == lastX && y == lastY) {
return; // nothing to draw
}
rx = Math.abs(rx);
ry = Math.abs(ry);
final float thrad = theta * (float) Math.PI / 180;
final float st = FloatMath.sin(thrad);
final float ct = FloatMath.cos(thrad);
final float xc = (lastX - x) / 2;
final float yc = (lastY - y) / 2;
final float x1t = ct * xc + st * yc;
final float y1t = -st * xc + ct * yc;
final float x1ts = x1t * x1t;
final float y1ts = y1t * y1t;
float rxs = rx * rx;
float rys = ry * ry;
float lambda = (x1ts / rxs + y1ts / rys) * 1.001f; // add 0.1% to be sure that no out of range occurs due to
// limited precision
if (lambda > 1) {
float lambdasr = FloatMath.sqrt(lambda);
rx *= lambdasr;
ry *= lambdasr;
rxs = rx * rx;
rys = ry * ry;
}
final float R =
FloatMath.sqrt((rxs * rys - rxs * y1ts - rys * x1ts) / (rxs * y1ts + rys * x1ts))
* ((largeArc == sweepArc) ? -1 : 1);
final float cxt = R * rx * y1t / ry;
final float cyt = -R * ry * x1t / rx;
final float cx = ct * cxt - st * cyt + (lastX + x) / 2;
final float cy = st * cxt + ct * cyt + (lastY + y) / 2;
final float th1 = angle(1, 0, (x1t - cxt) / rx, (y1t - cyt) / ry);
float dth = angle((x1t - cxt) / rx, (y1t - cyt) / ry, (-x1t - cxt) / rx, (-y1t - cyt) / ry);
if (sweepArc == 0 && dth > 0) {
dth -= 360;
} else if (sweepArc != 0 && dth < 0) {
dth += 360;
}
// draw
if ((theta % 360) == 0) {
// no rotate and translate need
arcRectf.set(cx - rx, cy - ry, cx + rx, cy + ry);
p.arcTo(arcRectf, th1, dth);
} else {
// this is the hard and slow part :-)
arcRectf.set(-rx, -ry, rx, ry);
arcMatrix.reset();
arcMatrix.postRotate(theta);
arcMatrix.postTranslate(cx, cy);
arcMatrix.invert(arcMatrix2);
p.transform(arcMatrix2);
p.arcTo(arcRectf, th1, dth);
p.transform(arcMatrix);
}
}