2016-09-02 9 views
0

私のプロジェクトでは、ユーザーが入力した画像、名前、会社、会場、日時などの単純なフォームフィールドを使用しています。しかし、詳細を入力する前に、3つの定義済みの招待状テンプレート(画像)を含むテンプレート選択セクションをユーザーに提供します。 記入されたユーザーの詳細をすべて、彼が選択した招待状のテンプレート(画像)に埋め込み、最後に招待状のテンプレートに記入されたすべての詳細を含む最終的な画像を表示することができます。Android:テンプレート+フォームデータから画像を作成

答えて

0
//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) 
} 

このように、必要なテンプレートごとにこれを呼び出します。

+0

どのように私は位置を定義することができますか、それは "NAME"を挿入する場所とすることができます –

+0

@SyedAsadAbbasZaidiそれは本当にあなたが配置する方法に依存します。標準をトップからボトムにしたい場合は、Xを5に設定し、Yの数を5から始めることができます(5,25,45,65など)。文字サイズ)。テキストがテンプレートの境界線を超えると、テキストが切り取られます。 Btw、私はテキスト塗料を含めるために私の答えを更新しました。 –

+0

私は困難に直面しています。実際、私のテキストの1つが長すぎるので、私は良い仕事をしている画面の中心に配置する必要があります。しかし、テキストはビットマップを超えてしまい、オーバーフローします。テキストが単語が分割されないという条件で超過したときに、行を自動的に変更する方法はありますか? –

関連する問題