android - Capture entire content of EditText into a picture -


i have print entire text of text field picture. reason is: have exchange messages unsupported utf-8 characters between android , other web clients. unsupported utf-8 characters mean missing fonts in android (see this topic here ). tried use direct way

bitmap b; edittext edittext = (edittext) findviewbyid(r.id.edittext); edittext.builddrawingcache(); b = edittext.getdrawingcache(); edittext.destroydrawingcache(); 

which works charm until have multiple lines: solution captures text visible user instead of complete text inside of long text field (scrollbars!).

i tried workaround generating picture stackoverflow answer. prints entire text not respect text formatting newlines. don't want handle stuff myself.

i forced use android 4.3 , earlier versions.

  1. is there smart way capture text pictures? if not:
  2. is possible modify code above work expected?

after searching 24 hours solution ran into solution webview. trick is

  1. generate view hold content avoid marker edittext on lower edge of view printed picture
  2. copy bitmap avoid problems software renderer after destroydrawingcache() when trying use bitmap.compress().

here code:

edittext edittext = (edittext) findviewbyid(r.id.edittext); textview textview = new textview(this.getapplicationcontext());  textview.settypeface(edittext.gettypeface()); textview.settext(edittext.gettext()); textview.measure(     view.measurespec.makemeasurespec(view.measurespec.unspecified, view.measurespec.unspecified),     view.measurespec.makemeasurespec(0, view.measurespec.unspecified)); textview.layout(0, 0, textview.getmeasuredwidth(), textview.getmeasuredheight()); textview.setdrawingcacheenabled(true); textview.builddrawingcache();  bitmap b = textview.getdrawingcache().copy(bitmap.config.argb_8888, false); textview.destroydrawingcache();  try{     string path = environment.getexternalstoragedirectory().tostring() + "/picture.png";     outputstream outputstream = new fileoutputstream(new file(path));     b.compress(bitmap.compressformat.png, 0, outputstream);     outputstream.flush();     outputstream.close(); } catch (exception e) {     e.printstacktrace(); } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -