Android -----paint cap join 理解 ,paint畫筆形狀設置


引自:http://www.2cto.com/kf/201501/370215.html

網上查了很多資料,對paint的里面的枚舉類cap join講的不是很透徹。在這里自己做一個比較深入的研究。

首先說Cap,比較形象的解釋就是 用來控制我們的畫筆在離開畫板時候留下的最后一點圖形,比如矩形,圓形等。不懂?那接着往下看。

先看看源碼

 

/**  * The Cap specifies the treatment for the beginning and ending of  
* stroked lines and paths. The default is BUTT.  */
public enum Cap {  
   /**      * The stroke ends with the path, and does not project beyond it.      */  
     BUTT    (0),  
        /**      * The stroke projects out as a semicircle, with the center at the      * end of the path.      */ 
          ROUND   (1),  
             /**      * The stroke projects out as a square, with the center at the end      * of the path.      */  
               SQUARE  (2);    
                 private Cap(int nativeInt) {  
                        this.nativeInt = nativeInt;   
                          }     
                          final int nativeInt; 
                          } 

和Cap類似,看源碼也就看出了默認是MITER,其他具體形狀還是難以理解。接着看圖:

 

 

MITER \
ROUND \
BEVEL \

 

上表就是三種樣式的區別,區別明顯,在此不再贅述。

引用:

* setStrokeCap(Paint.Cap cap);   
 
    * 當畫筆樣式為STROKE或FILL_OR_STROKE時,設置筆刷的圖形樣式,如圓形樣式   

    * Cap.ROUND,或方形樣式Cap.SQUARE    
    *    

     * setSrokeJoin(Paint.Join join);   

    * 設置繪制時各圖形的結合方式,如平滑效果等   

 paint 默認畫筆為矩形,即如果要用圓形畫筆,則在paint定義里面加上

    paint.setStrokeJoin(Paint.Join.ROUND);    
        paint.setStrokeCap(Paint.Cap.ROUND);

 如果想要從圓形切換成矩形需要

paint.setStrokeJoin(Paint.Join.MITER);   
paint.setStrokeCap(Paint.Cap.SQUARE);

主要是下面一句

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM