5

I need to convert TextView into ImageView so I will be able to save the ImageView as an image in the sd card. How do I convert TextView into ImageView?

Thanks. (I saw the other questions but them are not realy answer my question).

Lesmana
  • 25,663
  • 9
  • 82
  • 87
guy1820
  • 93
  • 2
  • 10

2 Answers2

5

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

You can create an Bitmap of any View 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.

In the other way , you can take your whole rootview as a screen shot and you can save it into disc.

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

Community
  • 1
  • 1
King of Masses
  • 18,405
  • 4
  • 60
  • 77
2
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;  
} 
Daniel Kutik
  • 6,997
  • 2
  • 27
  • 34
Pepe Peng
  • 51
  • 2