Search code examples
androidfontsbitmaprenderingeditbox

how to a display a bitmap in a editbox in android


i have two bitmap images ..and i need to merge the bitmaps with precise positioning of one bitmap over other and get a resultant bitmap (which is combination of both)

and the resultant bitmap is a font character and i want that bitmap to be displayed in a edit box where i am inputting text.

is it possible. Please help.


Solution

  • Try using ImageSpan object, creating it with the result bitmap and attaching it to the relevant part of text in edit box. Something like this:

    public class TestActivity extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
            TextView textView  = (TextView) findViewById(R.id.textview); 
            SpannableString ss = new SpannableString("abc"); 
            Drawable d = getResources().getDrawable(R.drawable.icon32); 
            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); 
            ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); 
            ss.setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); 
            textView.setText(ss); 
     }