简体   繁体   中英

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'. 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

drawCircle(float cx, float cy, float radius, Paint paint)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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