android - Blurry offset paths when canvas is scaled under hardware acceleration -
my application uses canvas scale can specify path points in meters instead of pixels. when scale canvas, draw line using path.lineto(), hardware acceleration on, line blurry , offset. not happen hardware acceleration off or canvas.drawline().
here code reproduce problem:
package com.example.canvasproblem; import android.app.activity; import android.content.context; import android.graphics.canvas; import android.graphics.paint; import android.graphics.path; import android.os.bundle; import android.view.view; public class mainactivity extends activity { protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(new myview(this)); } class myview extends view { paint pen = new paint(); public myview(context context) { super(context); pen.setstyle(paint.style.stroke); pen.setstrokewidth(1f); // 1 meters wide //this.setlayertype(layer_type_software, null); } protected void ondraw(canvas canvas) { float width_meter = 10.0f; // width of canvas in meters float width_pxl = canvas.getwidth(); // width of canvas in pixels float height_pxl = canvas.getheight(); // height of canvas in pixels canvas.save(); canvas.translate(width_pxl/2, height_pxl/2); // make center of canvas (0,0) canvas.scale(width_pxl/width_meter, width_pxl/width_meter); // convert meters // path path path = new path(); path.moveto(0, 0); path.lineto(0, 4); canvas.drawpath(path, pen); // line canvas.drawline(0, 0, 0, 4, pen); canvas.restore(); } } } here screenshot of problem output (the correct drawline() shown on top of lineto()):
the hardware 1024x768 tablet, running android 4.1.1. processor rockchip rk30.
my preference use path's hardware acceleration, rounded joins between points , speed. please let me know if doing wrong create problem. thank you
be gentle, first post.
this limitation of hardware accelerated renderer. paths rasterized @ native size before transform. in case, path transformed 1x4 texture. texture scaled @ draw time. work around this, scale path directly using path.transform(matrix). can use scaled coordinates when building path.
Comments
Post a Comment