android - how to get the bitmap from cusom imageview class? -


i want whole bimap map of custom class... getting null...i try every way don't getting write answer..

bitmap b = mboardtile.getdrawing(); used null value..

i m used view cache like..

      bitmap b = null;     try {         mboardtile.setdrawingcacheenabled(true);         mboardtile.measure(measurespec.makemeasurespec(0, measurespec.unspecified), measurespec.makemeasurespec(0, measurespec.unspecified));         mboardtile.layout(0, 0, mboardtile.getmeasuredwidth(), mboardtile.getmeasuredheight());         mboardtile.builddrawingcache(true);         b = mboardtile.getdrawingcache();     } catch (exception e) {         e.printstacktrace();     }` 

but again null value..

the custom class below..

public class boardtile extends imageview {  context mcontext;  int posx, posy;  arraylist<datavo> marraylistdta;  float width, height, newx, newy; arraylist<datavo> marraylistnew;  public boardtile(context context) {     super(context);     this.mcontext = context;     marraylistnew = new arraylist<datavo>(); }  @override protected void ondraw(canvas canvas) {     (int = 0; < marraylistnew.size(); i++) {         datavo mdatavo = marraylistnew.get(i);                  bitmap moriginalbitmap = mdatavo.getmbitmap();                 // scale target size                 moriginalbitmap = bitmap.createscaledbitmap(moriginalbitmap, mdatavo.getwidth_new(), mdatavo.getheight_new()/2, true);     //                   canvas mcanvas = new canvas(moriginalbitmap);                 canvas.drawbitmap(moriginalbitmap, 0, 0, null);     }  }  public void getdata(arraylist<datavo> marraylist) {      this.marraylistdta = marraylist;     (int = 0; < marraylistdta.size(); i++) {          newx = 480 * marraylistdta.get(i).getxcordi() / marraylistdta.get(i).getwidth();         newy = 800 * marraylistdta.get(i).getycordi() / marraylistdta.get(i).getheight();          width = newx * marraylistdta.get(i).getwidth() / marraylistdta.get(i).getxcordi();         height = newy * marraylistdta.get(i).getheight() / marraylistdta.get(i).getycordi();          datavo mdatavo = new datavo();         mdatavo.setxcordi_new((int) newx);         mdatavo.setycordi_new((int) newy);         mdatavo.setwidth_new((int) width);         mdatavo.setheight_new((int) height);         mdatavo.setmbitmap(marraylistdta.get(i).getmbitmap());         marraylistnew.add(mdatavo);      } } } 

i got solution getting whole bitmap custom class....

public static bitmap getbitmapfromview(view view) {     //define bitmap same size view      int fixwidth = 480;     int fixheight = 800;     int bit_width = 0;     int bit_height = 0;      bit_width = mimageviewbackgroud.getdrawable().getintrinsicwidth();     bit_height = mimageviewbackgroud.getdrawable().getintrinsicheight();      if (bit_width > fixwidth) {         bit_width = fixwidth;     }      if (bit_height > fixheight) {         bit_height = fixheight;     }      float ratio = math.min((float) 800 / bit_width, (float) 800 / bit_height);     int width = math.round((float) ratio * bit_width);     int height = math.round((float) ratio * bit_height);      bitmap returnedbitmap = bitmap.createbitmap(width, height,bitmap.config.argb_8888);     //bind canvas     canvas canvas = new canvas(returnedbitmap);     //get view's background     drawable bgdrawable =view.getbackground();     if (bgdrawable!=null)          //has background drawable, draw on canvas         bgdrawable.draw(canvas);     else          //does not have background drawable, draw white background on canvas         canvas.drawcolor(color.white);     // draw view on canvas     view.draw(canvas);     //return bitmap     return returnedbitmap; } 

hope code helps others....


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 ? -