bitmap - Resizing a custom marker on Android maps -


im quite new android forgive me if have missed something.

i've got following code displays custom marker on maps. custom marker has text on it. works point want resize marker amount when text longer.

the code had custom marker was,

   private bitmap drawtexttobitmap(final int mresid, final string mtext) {         resources resources = getresources();         // screen's density scale         float scale = resources.getdisplaymetrics().density;         bitmap bitmap = bitmapfactory.decoderesource(resources, mresid);         bitmap.config bitmapconfig = bitmap.getconfig();          if ( bitmapconfig == null ) {             bitmapconfig = bitmap.config.argb_8888;         }         bitmap = bitmap.copy(bitmapconfig, true);         canvas canvas = new canvas(bitmap);          paint paint = new paint(paint.anti_alias_flag);         // set font color         paint.setcolor(color.white);         // set font size , scale         paint.settextsize((int) (14 * scale));         // set shadow width         paint.setshadowlayer(1f, 0f, 1f, color.black);         // set anti-aliasing         paint.setantialias(true);         // make font bold         paint.settypeface(typeface.create(typeface.default, typeface.bold));          rect bounds = new rect();         paint.gettextbounds(mtext, 0, mtext.length(), bounds);         int x = (bitmap.getwidth() - bounds.width())/2;         int y = ((bitmap.getheight() + bounds.height())/2)-25;         canvas.drawtext(mtext, x, y, paint);          return bitmap;     } 

how can resize bitmap , increase font size accordingly without loosing resolution ? unfortunately cant give screenshots due licensing/permission issues.

found solution add following before creating canvas.

int newwidth = (int) (origbitmap.getwidth() * scalingfactor); int newheight = (int) (origbitmap.getheight() * scalingfactor); bitmap bitmap = bitmap.createscaledbitmap(origbitmap, newwidth, newheight, true); 

this scale bitmap accordingly. can scale font using same scalingfactor.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -