android - set bitmap which was created from RelativeLayout to imageView -


i have relativelayout , want convert bitmap this:

public static bitmap getbitmapfromview(view view) {     if (view != null)     { bitmap returnedbitmap = bitmap.createbitmap(view.getwidth(), view.getheight(),bitmap.config.argb_8888);     canvas canvas = new canvas(returnedbitmap);     drawable bgdrawable =view.getbackground();     if (bgdrawable!=null)          bgdrawable.draw(canvas);     else          canvas.drawcolor(color.white);     view.draw(canvas);     return returnedbitmap;     }     else          return null; } 

then create relativelayout cview in oncreate() method dynamically , set imageview this:

 dialer = (imageview) findviewbyid(r.id.imageview_ring);  dialer.setimagebitmap(getbitmapfromview(cview)); 

and error:

05-20 13:48:27.509: e/androidruntime(28367):    java.lang.runtimeexception: unable start activity   componentinfo{ru.biovamp.widget/ru.biovamp.widget.testcircleact}:  java.lang.illegalargumentexception: width , height must > 0 

i tried add bitmap imageview onstart() method, got same result. solution can use?

i've solved issue this:

  public  bitmap getbitmapfromview() {     this.measure(measurespec.makemeasurespec(createnewrelativelayoutparams().width, measurespec.unspecified),             measurespec.makemeasurespec(createnewrelativelayoutparams().height, measurespec.unspecified));     this.layout(0, 0, this.getmeasuredwidth(), this.getmeasuredheight());     bitmap returnedbitmap = bitmap.createbitmap(this.getmeasuredwidth(), this.getmeasuredheight(), bitmap.config.argb_8888);     canvas c = new canvas(returnedbitmap);     this.draw(c);     return returnedbitmap; } 

so solution should call measure() , layout() methods before drawing it.

oficial explaniton


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -