Canvas.drawVertices中的错误? (带有repro代码和logcat)
|
只需将此代码粘贴到一个简单的Android骨架项目中即可。
public final class DrawableView extends View
{
private float[] mVertices = {0, 0, 255, 0, 255, 255, 0, 255};
private float[] mTexCoords = {0, 0, 255, 0, 255, 255, 0, 255};
private short[] mIndices = {0, 2, 3, 0, 1, 2};
private int[] mColors = {Color.RED, Color.GREEN, Color.BLUE, Color.MAGENTA};
Context mContext;
BitmapShader mShader;
public DrawableView(Context context)
{
super(context);
mContext = context;
mShader = new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.icon), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setShader(mShader);
canvas.drawVertices(Canvas.VertexMode.TRIANGLES, 8, mVertices, 0, mTexCoords, 0, mColors, 0, mIndices, 0, 6, paint);
invalidate();
}
}
然后将其设置为主活动的onCreate中的主视图。
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new DrawableView(this));
}
这将使应用程序退出,没有错误,甚至没有“强制关闭”对话框。 Logcat也没有给我任何有用的信息(http://pastebin.com/c67NJnBz)!
但是,以下两个drawVertices调用均会产生所需的效果。
canvas.drawVertices(Canvas.VertexMode.TRIANGLES, 8, mVertices, 0, mTexCoords, 0, null, 0, mIndices, 0, 6, paint); // Works!
和
paint.setColor(Color.RED);
// paint.setShader(mShader);
canvas.drawVertices(Canvas.VertexMode.TRIANGLES, 8, mVertices, 0, mTexCoords, 0, mColors, 0, mIndices, 0, 6, paint); // Renders wireframe
难道我做错了什么?请帮助我确定这是否是Android API错误。
没有找到相关结果
已邀请:
1 个回复
系漏