[英]Animated canvas error: cannot convert from void to bitmap drawable
I've animated a canvas for my project, but I get an error: 'Cannot convert from void to bitmap drawable'. 我为项目的画布制作了动画,但是出现错误:“无法从void转换为可绘制的位图”。 Where is the fault? 哪里错了?
BitmapDrawable circle = (BitmapDrawable) canvas.drawCircle(canvas.getWidth()/2, (float) (canvas.getHeight()/1.8), 13, black);
For the context, this is the complete excerpt of the code 对于上下文,这是代码的完整摘录
protected void onDraw(Canvas canvas) {
Paint black = new Paint(Color.BLACK);
BitmapDrawable circle = (BitmapDrawable) canvas.drawCircle(canvas.getWidth()/2, (float) (canvas.getHeight()/1.8), 13, black);
if (x<0 && y <0) {
x = this.getWidth()/2;
y = this.getHeight()/2;
} else {
x += xVelocity;
y += yVelocity;
if ((x > this.getWidth() - circle.getBitmap().getWidth()) || (x < 0)) {
xVelocity = xVelocity*-1;
}
if ((y > this.getHeight() - circle.getBitmap().getHeight()) || (y < 0)) {
yVelocity = yVelocity*-1;
}
}
canvas.drawBitmap(circle.getBitmap(), x, y, null);
h.postDelayed(r, FRAME_RATE);
}
Your Radius parameter must be a float number, try to change it to 13f 您的Radius参数必须为浮点数,请尝试将其更改为13f
drawCircle(float cx, float cy, float radius, Paint paint)
BitmapDrawable circle = (BitmapDrawable) canvas.drawCircle(canvas.getWidth()/2, (float) (canvas.getHeight()/1.8), 13f, black);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.