android - How to render a tricky ass NinePatch? -


this thebasic idea, image ugly , pixelated. why???

 public class main extends activity {   /** called when activity first created. */   @override   public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);     imageview iv = (imageview) findviewbyid(r.id.iv);     bitmap bmap = bitmapfactory.decoderesource(getresources(), r.drawable.btn_default_normal);     ninepatchdrawable npd = new ninepatchdrawable(bmap, bmap.getninepatchchunk(), new rect(0,0,512,512), "name");     npd.mutate();     npd.setbounds(new rect(0,0,512,512));     npd.invalidateself();     bitmap bp = bitmap.createbitmap(512,512, bitmap.config.rgb_565);     canvas canvas = new canvas(bp);     npd.draw(canvas);     fileoutputstream ofo=null;     try {       ofo = openfileoutput("image", mode_world_readable);     } catch (ioexception e) {       e.printstacktrace();     }     bp.compress(bitmap.compressformat.png, 100, ofo);     intent intent = new intent(intent.action_view);     intent.putextra(intent.extra_stream, getfilestreampath("image").touri());     intent.settype("image/png");     //startactivity(intent);     iv.setimagedrawable(new bitmapdrawable(bp));   } } 

you're making infinitely more complicated needs be. set view in xml so:

<textview         android:background="@android:drawable/btn_default_small"                 android:layout_width="512px"         android:layout_height="wrap_content"         android:text="ninepatch view"         /> 

just using textview example. same work imageview, view, pretty widget. important thing remember use background attribute instead of src attribute imageview. src attribute stretch image is, won't respect ninepatch data.

if you're set on doing in code, use:

iv.setbackgroundresource(r.drawable.btn_default_small) 

as side note, device displaying on? mobile phones have 480 pixels width.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -