캔버스를 사용하여 배경 및 일부 텍스트가있는 Drawable을 만듭니다. 드로어 블은 EditText 내에서 복합 드로잉 가능으로 사용됩니다.안드로이드 캔버스 drawText 텍스트의 y- 위치
텍스트가 캔버스에 drawText()를 통해 그려지지만 일부 경우 그려지는 텍스트의 y 위치에 문제가 있습니다. 이 경우 일부 문자의 일부가 잘립니다 (이미지 링크 참조). 측위 문제없이
문자 : 위치 문제에
http://i50.tinypic.com/zkpu1l.jpg
문자 텍스트에는 'G', 'J', 'Q', 등 :
http://i45.tinypic.com/vrqxja.jpg
포함아래 코드에서 문제를 재현 할 수 있습니다.
전문가는 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();
}
}
올바른 방향으로 나를 가리켜 주셔서 감사합니다. canvas.drawText (text, 0, textBounds.height() - textBounds.bottom, paint); 해결책이었다. – darksaga