Drawing text size: one size fits all sizes and images
so I have a little problem:
My app is overlaying text onto an image canvas using paint:
textPaint = new Paint();
textPaint.setARGB(255, 255, 255, 255);
textPaint.setTypeface(memeType);
textPaint.setColor(defaultTextColor);
textPaint.setTextSize(textSize); //now 40
and then I just draw the text I got from the edittext:
canvas.drawText(text, x, y, text);
The problem is that text looks very different depending on three factors: image size, screen size, and screen size. So I'm trying to fix these issues to get one size to fit the text size. First, I update the text size based on the density of the display:
float density = getResources().getDisplayMetrics().density;
textSize = size * density;
Then I use this function I found on stackOverFlow to get the font size depending on the relationship:
private double getFont(double sizefont, double fontBase, double sizecanvas) {
double ratio = sizefont / fontBase;
return sizecanvas * ratio;
}
I'm not sure if this function is correct. I am using layout.getWidth as fontBase, sizecanvas is the size of the bitmap (and lol canvas) and sizefont is the font I want. Now use 40.
On large displays, the font appears slightly small and washed out. It looks good on a small display (5 inches).
Does anyone know how should I go about doing this? I am still working on it and I will keep you guys updated.
UPDATE:
Just to make things clearer:
The font size is 40, on the same screen, so the same dpi behaves differently if the images are 800x800 or 1200 x 1200. I want the font to behave the same across all my images and across devices. Thank!
source to share
No one has answered this question yet
Check out similar questions: