Comment rajouter bandeau noir comme snapchat

Fermé
lukas6410 - 7 avril 2022 à 09:37
BunoCS Messages postés 15472 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 25 mars 2024 - 14 avril 2022 à 09:27
Bonjour, je cherche a placer un bandeau noir derriere le texte voici la fonction qui dessine le texte
public void drawMultilineTextToBimap(Context context,String text,Bitmap bitmap){
        Resources resources = context.getResources();
        float scale = resources.getDisplayMetrics().density;
        Bitmap.Config bitmapConfig = bitmap.getConfig();
        if (bitmapConfig == null){
            bitmapConfig = Bitmap.Config.ARGB_8888;
        }
        Canvas canvas = new Canvas(bitmap);
        //draw rect text
        Paint paintRect = new Paint();
        paintRect.setColor(Color.BLACK);
        int heightrect = 100;
        int toprect = (bitmap.getHeight() - heightrect);
        int bottomRect = (bitmap.getHeight() + heightrect);
        canvas.drawRect(30, 30, 80, 80, paintRect);

        TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.WHITE);
        paint.setTextSize((int) (100 * scale));
        paint.setShadowLayer(1f, 0f, 1f, Color.BLACK);
        int textWidth = canvas.getWidth() - (int) (16 * scale);

        // init StaticLayout for text
        StaticLayout textLayout = new StaticLayout(
                text, paint, textWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);

        // get height of multiline text
        int textHeight = textLayout.getHeight();

        // get position of text's top left corner
        float x = (bitmap.getWidth() - textWidth)/2;
        float y = (bitmap.getHeight() - textHeight)/2;

        // draw text to the Canvas center
        canvas.save();
        canvas.translate(x, y);
        textLayout.draw(canvas);
        canvas.restore();
    }




Configuration: Windows / Firefox 98.0
A voir également:

1 réponse

BunoCS Messages postés 15472 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 25 mars 2024 3 894
14 avril 2022 à 09:27
Bonjour,

Pas très clair ta demande.. Peux-tu préciser ce que tu cherches à faire, avec une capture d'écran par ex, et ce que tu arrives déjà à faire ?
0