android,app绘制如何填充

时间:2016-04-22 13:22:49

标签: java android

我想在圆形等形状上使用填充方法。

它在一边工作但是当我尝试向左和向右填充时,应用停止 工作

我不知道自己做错了什么;也许有简单的方法。

这是填充/绘制功能(这不是完整的绘图代码)代码:

@Override
protected void onDraw(Canvas canvas) {
    if(z==true) {
        int a = (int) (x);
        int b = (int) (y);
        float x1,y1;
        if(canvasBitmap.getPixel(a,b)!=Color.RED)
        {
            for(;a<wo;a++)
            for(;b<ho;b++)
            if(canvasBitmap.getPixel(a,b)!=Color.RED && a<wo)
            {
                x1=(float) (a);
                y1=(float) (b);
                drawPaint.setStyle(Paint.Style.STROKE);
                canvas.drawBitmap(canvasBitmap, 0, 0, drawPaint);
                canvas.drawPath(drawPath, drawPaint);
            }
            else
            {
            a=wo+34;
            b=ho+34;
            }

        }
        else
        {

            drawPaint.setStyle(Paint.Style.STROKE);
            canvas.drawBitmap(canvasBitmap, 0, 0, drawPaint);
            canvas.drawPath(drawPath,drawPaint);

        }

    }
    else
    switch (pick) {

        case 1:
            drawPaint.setStyle(Paint.Style.STROKE);
            canvas.drawBitmap(canvasBitmap, 0, 0, drawPaint);
            drawCanvas.drawCircle(x,y,brushSize,drawPaint);
            break;
        case 2:
            drawPaint.setStyle(Paint.Style.STROKE);
            canvas.drawBitmap(canvasBitmap, 0, 0, drawPaint);
            drawCanvas.drawLine(x, y, brushSize, brushSize, drawPaint);
            break;
        case 3:
            drawPaint.setStyle(Paint.Style.STROKE);
            canvas.drawBitmap(canvasBitmap, 0, 0, drawPaint);
            drawCanvas.drawRect(x,brushSize,y,brushSize,drawPaint);
            break;
        default:
            drawPaint.setStyle(Paint.Style.STROKE);
            canvas.drawBitmap(canvasBitmap, 0, 0, drawPaint);
            canvas.drawPath(drawPath,drawPaint);




    }

}

1 个答案:

答案 0 :(得分:0)

为了填补一个圆圈:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawCircle(centerX, centerY, radius, mOverlayPaint);
}

mOverlayPaint = new Paint();
mOverlayPaint.setColor(Color.RED);
mOverlayPaint.setStrokeWidth(10);

onDraw中的这个简单调用将绘制一个红色圆圈,您可以根据需要计算/决定您的圆圈位置和半径