Soit un texte HTML multiligne comme celui-ci : <div style="color : rouge ;"><b>foo</b></div>. Il peut être multiligne car au moins une de ces conditions est vraie : a) le texte est très long ou b) il y a au moins un <br />.
Le but est de dessiner ce texte sur un canvevas, qui est construit à l'aide d'un Bitmap.
Le code minimal que j'ai écrit est le suivant (android.graphics.canvas, android.graphics.drawable.BitmapDrawable...) :
private BitmapDrawable addTextOnImage(BitmapDrawable bitmapDrawable bitmapDrawable) {
Bitmap bitmap = ..... ;
String caption = rich_editor_caption.getHtml() ;
StaticLayout mTextLayout_caption = StaticLayout.Builder.obtain(caption, 0, caption.length(), mTextPaint, bitmap.getWidth()).build() ;
Bitmap final_bitmap = Bitmap.createBitmap(bitmap.getWidth(), mTextLayout_caption.getHeight() + bitmap.getHeight(), Bitmap.Config.ARGB_8888) ;
Canvas canvas = nouveau Canvas(final_bitmap) ;
mTextLayout_caption.draw(canvas) ;
retourne nouveau BitmapDrawable(getActivity().getResources(), final_bitmap) ;
}
Si la légende de la variable contient du code HTML, ce dernier ne sera pas interprété. En d'autres termes : les balises seront effectivement affichées dans l'image résultante.
Est-il possible de faire interpréter ce code par l'application Android ?
Message édité le 17 mars 2019 à 11:20:01 par VivreUnEldorado