How to convert TextView to ImageView in android

I need to convert a TextView to an ImageView, so I can save the ImageView as an image on an SD card. How to convert TextView to ImageView?

Thanks. (I saw other questions, but they do not answer my question).

+5
source share
2 answers

Yes, there is a way to do this in two ways.

You can create a bitmap of any kind using buildDrawingCache() and getDrawingCache()

 TextView tv = (TextView)findViewById(R.id.textview); tv.buildDrawingCache(); ImageView img = (ImageView)findViewById(R.id.imageview); img.setImageBitmap(tv.getDrawingCache()); 

You can also check this answer for further reference.

On the other hand, you can take your entire rootview as a screenshot, and you can save it to disk.

This will help to achieve the above. How to programmatically take a screenshot on Android?

+5
source
 public static Bitmap convertViewToBitmap(View view) { view.measure( MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) ); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache(); return bitmap; } 
0
source

All Articles