0

i need to capture listview data and convert it into jpg or png image format , then saved into sd card. I captured only the data which is visible in the screen , but i am unable to capture the data which is avaialble in the scrollview.

So, please guide me guide me how to implement this.

My listview data

i am using the following code to capture the visible data.

View v1=btnCapture.getRootView();
public void gettingRootView(View v1)
 {
   if( v1 != null) 
   { 
   v1.setDrawingCacheEnabled(true); 
   v1.buildDrawingCache(); 
   Bitmap bm = v1.getDrawingCache();  
   try 
   { 
   if ( bm != null ) 
   {
    Log.e("file","filepath");
    savePhoto(bm);
   } 
   }
   catch(Exception e){e.printStackTrace();}
   }
 }

    public void savePhoto(Bitmap bmp)
    {
     Log.e("save photo","save photo");

    File fileFolder=new File(Environment.getExternalStorageDirectory(),"SMSREADING");
    fileFolder.mkdir();
    Calendar c=Calendar.getInstance();

    try
    {
    File fileName=new File(fileFolder,c.getTimeInMillis()+".jpg");
    FileOutputStream output=new FileOutputStream(fileName); 
    bmp.compress(Bitmap.CompressFormat.PNG,100,output);
    }
    catch(Exception ex){
    ex.printStackTrace(); 
    }
    }
koti
  • 1,071
  • 3
  • 15
  • 35
  • You could technically scroll the list view and capture the visible data and create a large bitmap by appending to it... to start out with set the bitmap cache to true and scroll to the listview top, get the bitmap and save it, then offset your scroll by the height of the screen and repeat the process... An other idea is to read the data and "build" an image and not actually capture it... what code are you using to capture the visible portion of the listview right now? – Ali Sep 12 '13 at 05:30
  • I edited my question by adding code for capturing visible data. @Ali – koti Sep 12 '13 at 05:38
  • Thanks, but I changed my mind/answer... try doing what I recommend below. As long as you can make a style sheet that closely mimics the look on the phone it should be all good, you can even set your html page's width in pixels by getting it from the `DisplayMetrics` on the phone. – Ali Sep 12 '13 at 05:41
  • ok,thankyou for your response,but how to create html from my data ? – koti Sep 12 '13 at 05:52
  • As mentioned below. You should have your data in a `List` or something. If you have it in a `List` you can use a templating engine like `Velocity`, if you have it as XML data you can just use XSLT. You don't need an "android" specific solution to that, if it works in Java it should work here. – Ali Sep 13 '13 at 01:15

1 Answers1

0

You can create HTML from your data using one of the many templating libraries out there like, if you have a String list Apache's Velocity might work well. After you create your HTML you can use java-html2image to convert your html to an image.

Ali
  • 12,354
  • 9
  • 54
  • 83