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).
TextView tv = (TextView)findViewById(R. id. textview); tv. buildDrawingCache(); ImageView img = (ImageView)findViewById(R.
Do you mean you want to put a TextView in fromt of an ImageView? You can't do this simply with a LinearLayout because this puts all views in a line side by side.
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?
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With