Android custom map marker, canvas drawing and image sizing -


i'm trying create custom marker in image below, either outline or drop-shadow if possible. rectangle inside represents dynamic image.

enter image description here

anyway, got basics down, can't figure out how change image's size, because can define top left offset point , rest of canvas gets filled image down bottom right edge, covering background. have no idea how create triangle pointing down, tried rotating canvas, drawing rectangle , rotating (see second code snippet), doesn't work because doesn't rotate around center. ideas? doing "properly"? right way build custom markers or slow / not optimal?

    //image marker - red background image on top     latlng vogel3 = new latlng(mylat+0.0005,mylong+0.0005);     bitmap.config conf = bitmap.config.argb_8888;     bitmap bmp = bitmap.createbitmap(40, 40, conf);     canvas canvas = new canvas(bmp);      paint color = new paint();     color.setcolor(color.red);      canvas.drawrect(0, 0, 40, 40, color);     canvas.drawbitmap(bitmapfactory.decoderesource(getresources(),         r.drawable.spatz_adult), 3, 5, color);      //canvas1.drawtext("bird", 30, 40, color);      //add marker map     map.addmarker(new markeroptions().position(vogel3)         .icon(bitmapdescriptorfactory.frombitmap(bmp))         .title("custom marker")         .snippet("eeeeeeeeeep")       //.anchor(0.5f, 1)     ); 

~

//trying draw triangle canvas.save(); canvas.rotate(45);         canvas.drawrect(0, 0, 40, 40, color); canvas.restore(); 

try following sample code resize image , worked me.

// resize image public bitmap resizebitmap(string imagepath,int targetw, int targeth) {     bitmapfactory.options bmoptions = new bitmapfactory.options();     bmoptions.injustdecodebounds = true;     bitmapfactory.decodefile(imagepath, bmoptions);     int photow = bmoptions.outwidth;     int photoh = bmoptions.outheight;      int scalefactor = 1;     if ((targetw > 0) || (targeth > 0)) {         scalefactor = math.min(photow/targetw, photoh/targeth);             }      bmoptions.injustdecodebounds = false;     bmoptions.insamplesize = scalefactor;     bmoptions.inpurgeable = true;      return bitmapfactory.decodefile(imagepath, bmoptions);             } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -