繁体   English   中英

动画画布错误:无法从void转换为可绘制的位图

[英]Animated canvas error: cannot convert from void to bitmap drawable

我为项目的画布制作了动画,但是出现错误:“无法从void转换为可绘制的位图”。 哪里错了?

BitmapDrawable circle = (BitmapDrawable) canvas.drawCircle(canvas.getWidth()/2, (float) (canvas.getHeight()/1.8), 13, black);

对于上下文,这是代码的完整摘录

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);


    } 

您的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM