Canvas.drawVertices(...) ничего не рисуетAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Canvas.drawVertices(...) ничего не рисует

Сообщение Anonymous »

Следующий класс — это представление красного треугольника:

Код: Выделить всё

public class FreeStyleViewII extends View {

private final Paint paint = new Paint();
private final int[] colors = new int[] {
Color.RED,
Color.RED,
Color.RED,
0xFF000000, 0xFF000000, 0xFF000000
};
private final float[] verts = new float[] {
1f/2f * 200f, 1f/4f * 200f,
1f/4f * 200f, 3f/4f * 200f,
3f/4f * 200f, 3f/4f * 200f
};
private final Path path = new Path();
{
path.moveTo(1/2 * 200, 1/4 * 200);
path.lineTo(1/4 * 200, 3/4 * 200);
path.lineTo(3/4 * 200, 3/4 * 200);
path.lineTo(1/2 * 200, 1/4 * 200);
}

private final RectF bounds = new RectF();

public FreeStyleViewII(Context context) {
super(context);
}

public FreeStyleViewII(Context context, AttributeSet attrs) {
super(context, attrs);
}

public FreeStyleViewII(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
protected void onDraw(Canvas canvas) {
canvas.clipRect(bounds);
canvas.drawRGB(0, 0, 0);

paint.setStyle(Style.FILL);
paint.setColor(Color.RED);

// HERE. WHY DRAWVERTICES DOESN'T WORK BUT DRAWPATH DOES?...
canvas.drawVertices(Canvas.VertexMode.TRIANGLES, verts.length, verts, 0, null, 0, colors, 0, null, 0, 0, paint);
// canvas.drawPath(path, paint);

paint.setStyle(Style.STROKE);
paint.setColor(Color.LTGRAY);
canvas.drawLine(0, bounds.bottom / 2, bounds.right, bounds.bottom / 2, paint);
canvas.drawLine(bounds.right / 2, 0, bounds.right / 2, bounds.bottom, paint);

// Delay
try {
Thread.sleep(30);
} catch (InterruptedException e) { }

invalidate();

}

@Override
public void onSizeChanged(int w, int h, int oldW, int oldH) {
bounds.set(1, 1, w - 1, h - 1);
System.out.println(bounds.left + " " + bounds.top + " " + bounds.right + " " + bounds.bottom);

verts[0] = bounds.left + ((bounds.right - bounds.left) * (1f / 2f));
verts[1] = bounds.top + ((bounds.bottom - bounds.top)  * (1f / 4f));
System.out.println(" Point: X ----> " + verts[0] + " | Y ----> " + verts[1]);

verts[2] = bounds.left + ((bounds.right - bounds.left) * (1f / 4f));
verts[3] = bounds.top + ((bounds.bottom - bounds.top)  * (3f / 4f));
System.out.println(" Point: X ----> " + verts[2] + " | Y ----> " + verts[3]);

verts[4] = bounds.left + ((bounds.right - bounds.left) * (3f / 4f));
verts[5] = bounds.top + ((bounds.bottom - bounds.top)  * (3f / 4f));
System.out.println(" Point: X ----> " + verts[4] + " | Y ----> " + verts[5]);

path.reset();

path.moveTo(verts[0], verts[1]);
path.lineTo(verts[2], verts[3]);
path.lineTo(verts[4], verts[5]);
path.lineTo(verts[0], verts[1]);

}
}
Когда я использую метод Canvas.drawPath, он работает нормально. Однако, если я перейду на Canvas.drawVertices, он ничего не нарисует. Я проверил, что сказано в разделе «Ошибка» в Canvas.drawVertices? (с кодом воспроизведения и logcat) и метод drawVertices() ничего не рисовали на Android Canvas, но в моем случае результат тот же.

Я использую AndroVM (v 4.1.1) в VirtualBox (v 4.1.22) для тестирования. Может быть, это эмулятор?

Есть идеи?

Подробнее здесь: https://stackoverflow.com/questions/146 ... ws-nothing
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»