android - AndroidSVG fuzzy edges on image -
i want display barcode on android. input svg string. svg library use androidsvg. used sample code library website , seem fine. when zoom on image, distorted edges (anti-alias?). tried disable flags. image still has fuzzy edges. can wrong code?
picture: try zoom max, see fuzzy edges.
code:
private void loadqrcode(string svgstring) { svg svg = null; try { svg = svg.getfromstring(svgstring); } catch (svgparseexception e) { e.printstacktrace(); } if (svg.getdocumentwidth() != -1) { int widthpx = utils.pxfromdp(400); int heightdp = utils.pxfromdp(300); svg.setdocumentwidth(widthpx); svg.setdocumentheight(heightdp); int width = (int) math.ceil(svg.getdocumentwidth()); int height = (int) math.ceil(svg.getdocumentheight()); bitmap newbm = bitmap.createbitmap(width, height, bitmap.config.argb_8888); canvas bmcanvas = new canvas(newbm); final drawfilter filter = new paintflagsdrawfilter(paint.anti_alias_flag| paint.filter_bitmap_flag | paint.dither_flag, 0); bmcanvas.setdrawfilter(filter); barcode.setlayertype(view.layer_type_software,null); bmcanvas.drawrgb(255, 255, 255); svg.rendertocanvas(bmcanvas); barcode.setimagebitmap(newbm); } }
if edges of bars not lie exactly on pixel boundaries, anti-aliasing. on high resolution screen, should not visible.
however, in code, rendering svg bitmap , setting bitmap imageview. if imageview has size larger bitmap - ie. greater 400 x 300, anti-aliased pixels in bitmap rendered larger , more visible.
one solution avoid using bitmap. use picture
/picturedrawable
instead. way barcode rendered @ highest quality no matter size is. vector graphics supposed be.
follow example on page:
http://bigbadaboom.github.io/androidsvg/use_with_imageview.html
so code should following:
private void loadqrcode(string svgstring) { try { svg svg = svg.getfromstring(svgstring); barcode.setlayertype(view.layer_type_software,null); drawable drawable = new picturedrawable(svg.rendertopicture()); barcode.setimagedrawable(drawable); } catch (svgparseexception e) { e.printstacktrace(); } }
if reason need use bitmaps - maybe caching them or - should watch changes in size of imageview
, recreate bitmap @ new size. bitmap same size imageview
assigned.
Comments
Post a Comment