1

I'm building an Android app where I need to overlay styled text on images using Canvas and Paint. I’ve successfully drawn basic text, but I'm running into two main issues:

  1. Text appears jagged or pixelated on high-resolution devices.

  2. Applying multiple effects like shadows, outlines, and gradients makes the rendering inconsistent.

What I want to achieve:

  • Smooth, anti-aliased text rendering.

  • Multiple style effects (shadow, outline, gradient).

  • Scalable text that looks clean on various screen densities.

What I've tried:

  • Using Paint.ANTI_ALIAS_FLAG

  • Custom fonts via Typeface.createFromAsset()

  • Adjusting canvas scaling

Here is a minimal version of the code I’m using:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_image);
Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setTextSize(60);
paint.setShadowLayer(10, 5, 5, Color.BLACK);
canvas.drawText("Test Text", 100, 100, paint);
imageView.setImageBitmap(mutableBitmap);```
asked Aug 5 at 12:19
1
  • hey, you can try so increase the height and width of the mutable bitmap so it will render at higher resolution by default. Try to balance quality and performance as you need , also can you post some images of how bad it looks like Commented Aug 6 at 9:53

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.