android - I converted the linear layout into Bitmap image but when saving it in folder the image is empty -


below code. here captures image not saved in specified folder, instead creates empty folder in name. code running fine capturing image not saving view in folder.since new android dont know how solve this. thanx in advance

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/linearlayout01"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="@drawable/ic_launcher"     android:orientation="vertical" >      <button         android:id="@+id/button01"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="capture" >     </button>      <imageview         android:id="@+id/imageview01"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:visibility="gone">     </imageview>      <listview         android:id="@+id/listview1"         android:layout_width="match_parent"         android:layout_height="wrap_content" >     </listview>  </linearlayout>       public class mainactivity extends activity implements onclicklistener {          linearlayout view;         button mybtn;         imageview view2;         imageview i;         layoutinflater inflater;          string[] items = { "multiply 2 numbers below 100",                 "multiply 2 numbers above 100", "multiply 2 digit numbers",                 "squaring number", "easy squaring number ends 1",                 "easy squaring number ends 5",                 "easy multiply number 11",                 "multiply 2 numbers condition",                 "finding square of adjacent number: 1 above",                 "finding square of adjacent number: 1 below",                 "checking number divisible 4 or not?",                 "multiply number 12?", "gbbbbbbbbbb", "gbbbbbbbbbbbbb",                 "gbbbbbbbbbbbbb", "gbbbbbbbbbb", "gbbbbbbbbbb", "bggggggggg",                 "bggggggggggggg","multiply 2 numbers above 100", "multiply 2",                 "squaring number", "easy squaring number ends 1",                 "easy squaring number ends 5",                 "easy multiply number 11",                 "multiply 2 numbers condition",                 "finding square of adjacent number: 1 above",                 "finding square of adjacent number: 1 below",                 "checking number divisible 4 or not?",                 "multiply number 12?", "gbbbbbbbbbb", "gbbbbbbbbbbbbb",                 "gbbbbbbbbbbbbb", "gbbbbbbbbbb", "gbbbbbbbbbb", "bggggggggg",                 "bggggggggggggg" };         listview l1;          @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_main);             layoutinflater inflater = (layoutinflater)                     .getsystemservice(layout_inflater_service);             l1 = (listview) findviewbyid(r.id.listview1);             mybtn = (button) findviewbyid(r.id.button01);             = (imageview) findviewbyid(r.id.imageview01);              arrayadapter<string> adapter = new arrayadapter<string>(                     mainactivity.this, android.r.layout.simple_list_item_1,                     android.r.id.text1, items);             l1.setadapter(adapter);             mybtn.setonclicklistener(this);          }         @override         public void onclick(view v) {              // todo auto-generated method stub             layoutinflater inflater = (layoutinflater)                     .getsystemservice(layout_inflater_service);             linearlayout root = (linearlayout) inflater.inflate(                     r.layout.activity_main, null);             root.setdrawingcacheenabled(true);              bitmap bmp = getbitmapfromview(this.getwindow().findviewbyid(                     r.id.listview1));             l1.setvisibility(view.gone);             i.setimagebitmap(bmp);             i.setvisibility(view.visible);          }          public bitmap getbitmapfromview(view v) {             v.setlayoutparams(new layoutparams(                     linearlayout.layoutparams.match_parent,                     linearlayout.layoutparams.match_parent));              listadapter adapter  = l1.getadapter();             int itemscount       = adapter.getcount();             int allitemsheight   = 0;             (int = 0; < itemscount; i++)             {     view childview      = adapter.getview(i, null, l1);                 childview.measure(measurespec.makemeasurespec(l1.getwidth(), measurespec.exactly),                         measurespec.makemeasurespec(0, measurespec.unspecified));                  childview.layout(0, 0, childview.getmeasuredwidth(), childview.getmeasuredheight());                 childview.setdrawingcacheenabled(true);                 childview.builddrawingcache();                  allitemsheight+=childview.getmeasuredheight();           }             v.layout(0, 0, v.getmeasuredwidth(),allitemsheight);                bitmap b = bitmap.createbitmap(v.getmeasuredwidth(),allitemsheight,                     bitmap.config.argb_8888);              canvas c = new canvas(b);             v.draw(c);            // return b;              string root = environment.getexternalstoragedirectory() + "/photoemail";               file file = new file(root);                file.mkdirs();               file file1 = new file(root + "/" +"images"+ ".png");               system.out.println(file1);               try {                 fileoutputstream fos = new fileoutputstream(file1);                  if (fos != null) {                             b.compress(bitmap.compressformat.png, 90, fos);                             //system.out.println("fos");                           fos.close();                            }             } catch (filenotfoundexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();      }             return b;     }     } 


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -