android - how to convert whole content of scrollview to bitmap -


i trying convert scrollview bitmap, bitmap returns null. don't know how manage, please give me solution achieve this.
want whole scrollview content bitmap in order create pdf afterwards.
following code:

    @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         requestwindowfeature(window.feature_no_title);         setcontentview(r.layout.activity_first__resume__screen);         rlv = (relativelayout) findviewbyid(r.id.rltv_layout);         rlt_layoutwhole = (relativelayout) findviewbyid(r.id.rlv_whole);         srvw = (scrollview) findviewbyid(r.id.scrollview1);         // view u = ((activity) mcontext).findviewbyid(r.id.scrollview1);         random rnd = new random();         int prevtextviewid = 0;         relativelayout.layoutparams params1 = new relativelayout.layoutparams(                 layoutparams.wrap_content, layoutparams.wrap_content);         (int = 0; < 15; i++) {             final textview textview = new textview(this);             textview.settext("text " + i);             textview.settextcolor(rnd.nextint() | 0xff000000);              int curtextviewid = prevtextviewid + 1;             textview.setid(curtextviewid);             final relativelayout.layoutparams params = new relativelayout.layoutparams(                     relativelayout.layoutparams.fill_parent,                     relativelayout.layoutparams.wrap_content);              params.addrule(relativelayout.below, prevtextviewid);             params.setmargins(10, 0, 0, 0);             textview.setlayoutparams(params);              prevtextviewid = curtextviewid;             rlv.addview(textview, params);         }  //      rlt_layoutwhole.setdrawingcacheenabled(true); //      rlt_layoutwhole.builddrawingcache(); //      bitmap bm = rlt_layoutwhole.getdrawingcache();         rlt_layoutwhole.setdrawingcacheenabled(true);         rlt_layoutwhole.refreshdrawablestate();           bitmap bitmap = rlt_layoutwhole.getdrawingcache();           rlt_layoutwhole.setdrawingcacheenabled(false);  //      bitmap bitmap = bitmap.createbitmap(rlt_layoutwhole.getwidth(), //              rlt_layoutwhole.getheight(), bitmap.config.argb_8888); //      canvas canvas = new canvas(bitmap); //      rlt_layoutwhole.draw(canvas); //      createpdf(bitmap); //           //****************************************************************88 //      int totalheight = srvw.getchildat(0).getheight(); //      int totalwidth = srvw.getchildat(0).getwidth(); // //      bitmap b = getbitmapfromview(srvw,1200,300);              // //      //save bitmap //      string extr = environment.getexternalstoragedirectory()+"/folder/"; //      string filename = "report.jpg"; //      file mypath = new file(extr, filename); //      fileoutputstream fos = null; //      try { //          fos = new fileoutputstream(mypath); //          b.compress(bitmap.compressformat.jpeg, 100, fos); //          fos.flush(); //          fos.close(); //          mediastore.images.media.insertimage(mcontext.getcontentresolver(), b, "screen", "screen"); //      }catch (filenotfoundexception e) { //          // todo auto-generated catch block //          e.printstacktrace(); //      } catch (exception e) { //          // todo auto-generated catch block //          e.printstacktrace(); //      }         //********************************************************************************************8          int height = math.min(500, 500);          //  float percent = height / (float)totalheight;             bitmap canvasbitmap = bitmap.createbitmap((int)(1500),(int)(1500), bitmap.config.argb_8888);            canvas canvas = new canvas(canvasbitmap);             drawable bgdrawable = srvw.getbackground();            if (bgdrawable != null)               bgdrawable.draw(canvas);            else               canvas.drawcolor(color.black);             canvas.save();            //canvas.scale(100, percent);            srvw.draw(canvas);            canvas.restore();          createpdf(canvasbitmap);      }      public bitmap getbitmapfromview(view view, int totalheight, int totalwidth) {          bitmap returnedbitmap = bitmap.createbitmap(totalwidth,totalheight , 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;     }        public bitmap getbitmapfromview(view view) {         view.setdrawingcacheenabled(true);         view.refreshdrawablestate();         bitmap bitmap = view.getdrawingcache();         view.setdrawingcacheenabled(false);         return bitmap;     } 


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -