Android - 无法在画布中绘制位图

时间:2015-09-25 20:14:06

标签: android bitmap android-canvas

我有以下代码可以使用:

protected void onDraw(Canvas canvas) {    
    canvas.drawRect(undoButtonRectF, buttonPaint);
    canvas.drawPath(undoButtonArrow, buttonArrowPaint);

无论如何,当我用以下内容交换时:

protected void onDraw(Canvas canvas) {        
        undoButtonBitmap = Bitmap.createBitmap((int) undoButtonRectF.width(), (int) undoButtonRectF.height(), Bitmap.Config.ARGB_8888);

        Canvas ca = new Canvas(undoButtonBitmap);

        ca.drawRect(undoButtonRectF, buttonPaint);
        ca.drawPath(undoButtonArrow, buttonArrowPaint);

        canvas.drawBitmap(undoButtonBitmap, undoButtonRectF.left, undoButtonRectF.top, buttonPaint);

什么都没画。怎么会发生这种情况?我是以错误的方式使用位图吗?拜托,帮帮我!!!

1 个答案:

答案 0 :(得分:1)

我认为存在协调器错误。

错误是undoButtonRectF包含“canvas”的偏移,而不是“ca”,你应该在调用之前调整或删除顶部/左侧偏移量

 ca.drawRect(undoButtonRectF, buttonPaint);
 ca.drawPath(undoButtonArrow, buttonArrowPaint);

对吗?