Create bitmap and draw text into bitmap Android example

public class ApokusActivity extends Activity {
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}
 
	private static class SampleView extends View {
 
		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);
 
		}
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
 
			canvas.drawColor(Color.GREEN);
 
           Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
           Canvas c = new Canvas(b);
           c.drawRect(0, 0, 200, 200, paint);
 
           paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
           paint.setTextSize(40);
           paint.setTextScaleX(1.f);
           paint.setAlpha(0);
           paint.setAntiAlias(true);
           c.drawText("Your text", 30, 40, paint);
           paint.setColor(Color.RED);
 
           canvas.drawBitmap(b, 10,10, paint);
		}
 
	}
}

draw-text-into-bitmap-android

This entry was posted in Android Examples Code, Bitmap, drawing and tagged , . Bookmark the permalink.


Comments are closed.



33,525 views