android与j2me移植之clipRect

j2me移动到android时,你可能须要用到clipRect这个方法,咱们用它来截取必定区域,让来看看j2me和android有什么不一样吧java

 

Android code:android

  1. canvas.save();//保存当前状态   
  2. canvas.clipRect(x,y, x+width, y+height)   
  3. canvas.restore();//释放当前状态  

 

J2ME code:canvas

  1. int clipX = g.getClipX();   
  2. int clipY = g.getClipY();   
  3. int clipWidth = g.getClipWidth();   
  4. int clipHeight = g.getClipHeight();   
  5. g.clipRect(x, y, width, height);   
  6. g.setClip(clipX, clipY, clipWidth, clipHeight);//释放当前状态  

 

比较两段代码,Android比较简洁,要注意的是canvas.clipRect(left, top, right, bottom),它们的坐标为left, top, right, bottom,因此要加上x,y,这一点在刚开始开发j2me转android时会发现有些区别,也容易忽略,像fillRect,drawRect等方法也和j2me有区别!spa

 

j2me需用setClip释放当前状态,而android没必要!rest

相关文章
相关标签/搜索