我试图在非标准形状上绘画,例如它对用户显示完全透明的视图,但他只能在视图的某些区域(如动物形状)绘制这一切都是因为动物器官形状将在回到油漆视图。
前层将是透明视图,我将用于绘画。
@Override
protected void onDraw(Canvas canvas) {
boolean containsBG = props.containsKeyAndNotNull(
TiC.PROPERTY_BACKGROUND_COLOR);
canvas.drawColor(containsBG ?
TiConvert.toColor(props, TiC.PROPERTY_BACKGROUND_COLOR) :
TiConvert.toColor("transparent"));
canvas.drawBitmap(tiBitmap, 0, 0, tiBitmapPaint);
for (int i = 0; i < maxTouchPoints; i++) {
if (tiPaths[i] != null) {
canvas.drawPath(tiPaths[i], tiPaint);
}
}
}
private void touch_start(int id, float x, float y) {
tiPaths[id] = new Path();
tiPaths[id].moveTo(x, y);
tiX[id] = x;
tiY[id] = y;
}
private void touch_move(int id, float x, float y) {
if (tiPaths[id] == null) {
tiPaths[id] = new Path();
tiPaths[id].moveTo(tiX[id], tiY[id]);
}
tiPaths[id].quadTo(tiX[id], tiY[id], (x + tiX[id]) / 2, (y + tiY[id]) / 2);
tiX[id] = x;
tiY[id] = y;
}
@Override
public boolean onTouchEvent(MotionEvent mainEvent) {
for (int i = 0; i < mainEvent.getPointerCount(); i++) {
int id = mainEvent.getPointerId(i);
float x = mainEvent.getX(i);
float y = mainEvent.getY(i);
int action = mainEvent.getAction();
if (action > 6) {
action = (action % 256) - 5;
}
switch (action) {
case MotionEvent.ACTION_DOWN:
finalizePath(id);
touch_start(id, x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(id, x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
finalizePath(id);
invalidate();
break;
}
}
return true;
}
public void finalizePath(int id) {
if (tiPaths[id] != null) {
tiCanvas.drawPath(tiPaths[id], tiPaint);
tiPaths[id].reset();
tiPaths[id] = null;
}
}
public void finalizePaths() {
for (int i = 0; i < maxTouchPoints; i++) {
if (tiPaths[i] != null) {
tiCanvas.drawPath(tiPaths[i], tiPaint);
tiPaths[i].reset();
tiPaths[i] = null;
}
}
}
任何人都可以帮助实现这一目标。提前谢谢
答案 0 :(得分:0)
如果你有面具并且在使用你的应用程序时它不会改变,也许你可以试试这个: