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:
Text appears jagged or pixelated on high-resolution devices.
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_FLAGCustom 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);```
-
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 likehanrv user– hanrv user2025年08月06日 09:53:16 +00:00Commented Aug 6 at 9:53