//template is the card template, strings is the details, x and y are the locations of the strings.
//The top left corner of the image is (0, 0), and the bottom right is (template.width, template.height)
private static Bitmap makeDetailedBitmap(final Bitmap template, final String[] strings, final float[] x, final float[] y)
{
Bitmap result = Bitmap.createBitmap(template.getWidth(), template.getHeight(), template.getConfig()); //Create the base image
Canvas canvas = new Canvas(result); //Create a canvas so we can draw onto the base image
canvas.drawBitmap(template, 0, 0, null); //Draw the template
//EDIT: Forgot to set the text paint
Paint p = new Paint();
//p.setTextAlign(Paint.Align.CENTER); //Uncomment if you want centered text
p.setTextSize(12); //Change as you please
p.setColor(Color.BLACK); //Change as you please
final int len = strings.length; //Assumes that the length of x and y are >= the length of strings
for (int i = 0; i < len; i++)
{
canvas.drawText(strings[i], x[i], y[i], p); //Draws text onto image
}
return result; //Returns image that was modified using the canvas (aka image with details)
}
このように、必要なテンプレートごとにこれを呼び出します。
どのように私は位置を定義することができますか、それは "NAME"を挿入する場所とすることができます –
@SyedAsadAbbasZaidiそれは本当にあなたが配置する方法に依存します。標準をトップからボトムにしたい場合は、Xを5に設定し、Yの数を5から始めることができます(5,25,45,65など)。文字サイズ)。テキストがテンプレートの境界線を超えると、テキストが切り取られます。 Btw、私はテキスト塗料を含めるために私の答えを更新しました。 –
私は困難に直面しています。実際、私のテキストの1つが長すぎるので、私は良い仕事をしている画面の中心に配置する必要があります。しかし、テキストはビットマップを超えてしまい、オーバーフローします。テキストが単語が分割されないという条件で超過したときに、行を自動的に変更する方法はありますか? –