Understanding Android Canvas Clipping

柔情痞子 提交于 2019-12-19 08:13:34

问题


I am having trouble finding an answer to this. Consider the clipping code below:

           boolean is_ok = mycanvas.clipRect(clip_left, clip_top, clip_right+1, clip_bottom+1);
       mycanvas.getClipBounds(clipRect);
       if (!is_ok ||
               clipRect.left != clip_left ||
               clipRect.top != clip_top ||
               clipRect.right != clip_right+1 ||
               clipRect.bottom != clip_bottom+1)
       {
           Log.i("DEBUG", "setClipping failed");
       }

When the clip bounds are returned they don't match what was just set. For example if clip_left, clip_top, clip_right, clip_bottom are (100,50,109, 59) then I would expect the clipping bounds to be (100, 50, 110, 60) given the code above. It isn't. getClipBounds() returns (100, 51, 110, 60).

Why is top = 51 when I just set it to 50? There's something under the hood I don't understand yet.


回答1:


OK, I need to read more clearly before asking questions. In case anyone is interested I'll answer this myself:

When setting a new clipRect, I assumed it would replace the prior clipping. This is NOT so. Instead it creates an intersection with the previous clipping. From the Android Developers page:

clipRect(float left, float top, float right, float bottom)

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.



来源:https://stackoverflow.com/questions/10941416/understanding-android-canvas-clipping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!