Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid bitmaps and capturing screen
    primarykey
    data
    text
    <p>I have an app that generates a report in a TableLayout with a variable number of TableRows. </p> <p>I use the following code to capture the Table into a bitmap: </p> <pre><code>TableLayout tl = (TableLayout)findViewById(R.id.CSRTableLayout); Bitmap csr = Bitmap.createBitmap(tl.getWidth(), tl.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(csr); tl.draw(canvas); </code></pre> <p>After I capture the screen as a bitmap, I attach it to an email using: </p> <pre><code>//folder already exists File file = new File(folder.getAbsolutePath()+"/CSR"+csrnum+".jpg"); BufferedOutputStream bos = null; FileOutputStream fos = null; try { fos=new FileOutputStream(file); bos=new BufferedOutputStream(fos); if(bos!=null) { try { csr.compress(Bitmap.CompressFormat.JPEG, 60, bos); } catch (OutOfMemoryError e) { Toast.makeText(CustomerReportActivity.this, "Out of Memory!", Toast.LENGTH_SHORT).show(); } finally { fos.flush(); fos.close(); bos.flush(); bos.close(); } } } catch (Exception e) { e.printStackTrace(); } if(file.exists()) { Intent i = new Intent(Intent.ACTION_SEND); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setType("message/rfc822"); String emailTo[] = {"***@****.***"}; i.putExtra(Intent.EXTRA_EMAIL,emailTo); i.putExtra(Intent.EXTRA_SUBJECT,"..."); i.putExtra(Intent.EXTRA_TEXT, "..."); i.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+file.getAbsolutePath())); startActivity(i); } else { Toast.makeText(CustomerReportActivity.this, "Error attaching report to email!", Toast.LENGTH_SHORT).show(); } </code></pre> <p>The problem is that sometimes the table can get quite large, such as 1600x2400dp. I have gotten an OutOfMemoryError on the line "Bitmap.createBitmap(...)" Is there an alternative method to capture the screen while not overflowing the VM heap? If I understand correctly, calling Bitmap.createBitmap(...) is creating a bitmap the full size that is all just plain white. Is it possible to create it with NO pixel data and only fill it in once I called csr.compress(...) so that way it stays small? Any ideas/suggestions are greatly appreciated! Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload