Skip to main content
added 141 characters in body
Source Link

Sadly I have too little reputation here to add picturesenter image description here

Looks still smooth when zooming with the resultscanvas.scale(): enter image description here

Sadly I have too little reputation here to add pictures with the results.

enter image description here

Looks still smooth when zooming with canvas.scale(): enter image description here

Grammar, spelling. Removed redundancies.
Source Link
Anko
  • 13.4k
  • 10
  • 55
  • 82

I don't know if following helps, but could be :-) To get a smoothsmoother intersection of two pathes even if you scale the canvaspaths, you can do the following : Before I intersect my pathes Icould scale them up . Afterbefore intersection Iand scale them down after. 

I don't know if thatsit's a good solution, but it worked well for me. ItsIt's also fast. In my example, I intersect a rounded path with a owncreated pattern I created ( stripes stripes). It looks still good even when scaling ( zooming )scaled.

Here my Code code:

sadlySadly I have to lesstoo little reputation here to add pictures to show whatswith the result of my code results.

I don't know if following helps, but could be :-) To get a smooth intersection of two pathes even if you scale the canvas you can do the following : Before I intersect my pathes I scale them up . After intersection I scale them down. I don't know if thats a good solution, but it worked for me. Its also fast. In my example I intersect a rounded path with a owncreated pattern ( stripes ). It looks still good when scaling ( zooming )

Here my Code :

sadly I have to less reputation here to add pictures to show whats the result of my code .

To get a smoother intersection of two paths, you could scale them up before intersection and scale them down after. 

I don't know if it's a good solution, but it worked well for me. It's also fast. In my example, I intersect a rounded path with a pattern I created (stripes). It looks good even when scaled.

Here my code:

Sadly I have too little reputation here to add pictures with the results.

Source Link

I don't know if following helps, but could be :-) To get a smooth intersection of two pathes even if you scale the canvas you can do the following : Before I intersect my pathes I scale them up . After intersection I scale them down. I don't know if thats a good solution, but it worked for me. Its also fast. In my example I intersect a rounded path with a owncreated pattern ( stripes ). It looks still good when scaling ( zooming )

Here my Code :

    Path mypath=new Path(<desiredpath to fill with a pattern>);
    String sPatternType=cpath.getsPattern();
    
    Path pathtempforbounds=new Path(cpath.getPath());
    RectF rectF = new RectF();
     if (sPatternType.equals("1")){
         turnPath(pathtempforbounds, -45);
     }
     pathtempforbounds.computeBounds(rectF, true);
     
     float ftop=rectF.top;
     float fbottom=rectF.bottom;
     float fleft=rectF.left;
     float fright=rectF.right;
     float xlength=fright-fleft;
     
     Path pathpattern=new Path();
     
     float ypos=ftop;
     float xpos=fleft;
     
     float fStreifenbreite=4f;
     
     while(ypos<fbottom){
         pathpattern.moveTo(xpos,ypos);
         xpos=xpos+xlength;
         pathpattern.lineTo(xpos, ypos);
         ypos=ypos+fStreifenbreite;
         pathpattern.lineTo(xpos, ypos);
         xpos=xpos-xlength;
         pathpattern.lineTo(xpos, ypos);
         ypos=ypos-fStreifenbreite;
         pathpattern.lineTo(xpos, ypos);
         pathpattern.close();
         ypos=ypos+2*fStreifenbreite;
         
     }
     
     // Original vergrössern
     
     scalepath(pathpattern,10);
     scalepath(mypath,10);
     
     if (sPatternType.equals("1")){
         Matrix mdrehen=new Matrix();
         RectF bounds=new RectF();
         pathpattern.computeBounds(bounds, true);
         mdrehen.postRotate(45, (bounds.right + bounds.left)/2,(bounds.bottom + bounds.top)/2);
         pathpattern.transform(mdrehen);
     }
     
     RectF rectF2 = new RectF();
     mypath.computeBounds(rectF2, true);
     
     Region clip = new Region();
     clip.set((int)(rectF2.left-100f),(int)(rectF2.top -100f), (int)(rectF2.right+100f),(int)( rectF2.bottom+100f));
     Region region1 = new Region();
     region1.setPath(pathpattern, clip);
     
     Region region2 = new Region();
     region2.setPath(mypath, clip);
     
     region1.op(region2, Region.Op.INTERSECT);
     
     
     Path pnew=region1.getBoundaryPath();
     
     
     scalepath(pnew, 0.1f);
     cpath.setPathpattern(pnew);




public void turnPath(Path p,int idegree){
     Matrix mdrehen=new Matrix();
     RectF bounds=new RectF();
     p.computeBounds(bounds, true);
     mdrehen.postRotate(idegree, (bounds.right + bounds.left)/2,(bounds.bottom + bounds.top)/2);
     p.transform(mdrehen);
}

public void scalepath(Path p,float fscale){
     Matrix mverkleinern=new Matrix();
     mverkleinern.preScale(fscale,fscale);
     p.transform(mverkleinern);
}

sadly I have to less reputation here to add pictures to show whats the result of my code .