簡體   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