How to add String on Bitmap Image in Android?

前端 未结 1 1639
遥遥无期
遥遥无期 2021-01-21 11:40

I want to add a string on bitmap image.I have a metod drawTextToBitmap,this method working success place string on bitmap image.But my bitmap image is very small li

1条回答
  •  有刺的猬
    2021-01-21 12:42

    Try this:

    public static Bitmap drawStringonBitmap(Bitmap src, String string, Point location, int color, int alpha, int size, boolean underline,int width ,int height) {
    
        Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());
    
        Canvas canvas = new Canvas(result);
        canvas.drawBitmap(src, 0, 0, null);
        Paint paint = new Paint();
        paint.setColor(color);
        paint.setAlpha(alpha);
        paint.setTextSize(size);
        paint.setAntiAlias(true);
        paint.setUnderlineText(underline);
        canvas.drawText(string, location.x, location.y, paint);
    
        return result;
    }
    

    0 讨论(0)
提交回复
热议问题