title: How to convert text of a TextView to bitmap in Android?
body: <p>I'm a beginner in Android development and am trying to develop a program where the user can convert the text being displayed in the TextView <em>(TextView is displaying a code 39 barcode font text which I've imported from assets)</em> to bitmap after pressing the "Convert to Bitmap!" button. I've tried searching around google but I've only managed to get answers like converting string to bitmap without guides on where to type the codes so I'm rather confuse on that. 
  I've tried running the program with the codes I tried typing out after googling around but it crashes everytime I press the convert button.</p>
  
  <p>Really hope that you can help! Thank you in advance! :D</p>
  
  <p>The following are my codes so far:-</p>
  
  <p>*<em>Edited with respect to Simon's code</em></p>
  
  <p><strong>At java:</strong></p>
  
  <pre><code>public class MainActivity extends Activity 
  implements OnClickListener {
      //Called when activity is first created
  
      TextView tv1;
      ImageView iv;
      Button b;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          TextView tv1 = (TextView) findViewById(R.id.txtV);  
          tv1.setDrawingCacheEnabled(true); 
  
          //To change to code 39 barCode font
          Typeface barcodefont = Typeface.createFromAsset(getAssets(),                 
                  "fonts/IDAutomationHC39M_FREE.otf");         
          TextView tv = (TextView) findViewById(R.id.txtV);         
          tv.setTypeface(barcodefont);
      }
  
      public void onClick(View v) {
  
          tv1.buildDrawingCache(); 
          iv.setImageBitmap(tv1.getDrawingCache()); 
      } 
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  }
  </code></pre>
  
  <p><strong>Logcat error:</strong></p>
  
  <pre><code>10-04 06:33:25.076: E/AndroidRuntime(1423): FATAL EXCEPTION: main
  10-04 06:33:25.076: E/AndroidRuntime(1423): java.lang.IllegalStateException: Could not find a method ConvertText(View) in the activity class com.example.txtvbitmapconverter.MainActivity for onClick handler on view class android.widget.Button with id 'btnConvert'
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.view.View$1.onClick(View.java:3578)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.view.View.performClick(View.java:4084)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.view.View$PerformClick.run(View.java:16966)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.os.Handler.handleCallback(Handler.java:615)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.os.Handler.dispatchMessage(Handler.java:92)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.os.Looper.loop(Looper.java:137)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.app.ActivityThread.main(ActivityThread.java:4745)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at java.lang.reflect.Method.invokeNative(Native Method)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at java.lang.reflect.Method.invoke(Method.java:511)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at dalvik.system.NativeStart.main(Native Method)
  10-04 06:33:25.076: E/AndroidRuntime(1423): Caused by: java.lang.NoSuchMethodException: ConvertText [class android.view.View]
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at java.lang.Class.getConstructorOrMethod(Class.java:460)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at java.lang.Class.getMethod(Class.java:915)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     at android.view.View$1.onClick(View.java:3571)
  10-04 06:33:25.076: E/AndroidRuntime(1423):     ... 11 more
  </code></pre>