Sto usando una tela per creare un Drawable con qualche sfondo e del testo. Il drawable è usato come un composto estraibile all'interno di un EditText.Draw canvas canvasTesto posizione y di testo
Il testo viene disegnato tramite drawText() sulla tela, ma in alcuni casi ho un problema con la posizione y del testo disegnato. In questi casi le parti di alcuni personaggi sono troncate (vedi link immagine).
caratteri senza emissione di posizionamento:
http://i50.tinypic.com/zkpu1l.jpg
Caratteri con emissione posizionamento, testo contiene 'g', 'j', 'q', ecc .:
http://i45.tinypic.com/vrqxja.jpg
È possibile trovare uno snippet di codice per riprodurre il problema di seguito.
Un esperto sa come determinare l'offset corretto per la posizione y?
public void writeTestBitmap(String text, String fileName) {
// font size
float fontSize = new EditText(this.getContext()).getTextSize();
fontSize+=fontSize*0.2f;
// paint to write text with
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.DKGRAY);
paint.setAntiAlias(true);
paint.setTypeface(Typeface.SERIF);
paint.setTextSize((int)fontSize);
// min. rect of text
Rect textBounds = new Rect();
paint.getTextBounds(text, 0, text.length(), textBounds);
// create bitmap for text
Bitmap bm = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888);
// canvas
Canvas canvas = new Canvas(bm);
canvas.drawARGB(255, 0, 255, 0);// for visualization
// y = ?
canvas.drawText(text, 0, textBounds.height(), paint);
try {
FileOutputStream out = new FileOutputStream(fileName);
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
} catch (Exception e) {
e.printStackTrace();
}
}
Grazie per avermi indicato nella giusta direzione. canvas.drawText (testo, 0, textBounds.height() - textBounds.bottom, paint); era la soluzione – darksaga