Java 在图形绘制中有多种字体

Java 在图形绘制中有多种字体,java,android,canvas,paint,Java,Android,Canvas,Paint,我正在尝试使用以下代码创建jpeg图像: Bitmap src = BitmapFactory.decodeResource(activity.getResources(), R.drawable.background_splash); // the original file yourimage.jpg i added in resources Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(

我正在尝试使用以下代码创建jpeg图像:

Bitmap src = BitmapFactory.decodeResource(activity.getResources(), R.drawable.background_splash); // the original file yourimage.jpg i added in resources
           Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);

            String yourText = "My custom Text adding to Image";

            Canvas cs = new Canvas(dest);
            Paint tPaint = new Paint();
            tPaint.setTextSize(35);
            tPaint.setColor(Color.BLUE);

        tPaint.setTypeface(Typeface.createFromAsset(getAssets(),
                    PATH_FONT_PUNJABI));

            cs.drawBitmap(src, 0f, 0f, null);
            float height = tPaint.measureText("yY");
            float width = tPaint.measureText(yourText);
            float x_coord = (src.getWidth() - width)/2;
            cs.drawText(yourText, x_coord, height+15f, tPaint); // 15f is to put space between top edge and the text, if you want to change it, you can
            try {
                dest.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/sdcard/ImageAfterAddingText.jpg")));
                // dest is Bitmap, if you want to preview the final image, you can display it on screen also before saving
               System.out.println("Image Created");
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }   
现在,我希望一些文本使用字体A,一些使用字体B。我如何才能做到这一点

谢谢


Aman

最简单的方法是使用两个单独的绘图文本命令。设置第一种字体,绘制字符串1,设置第二种字体,绘制字符串2。如果一个字符串紧跟在另一个字符串之后,您可以获得绘制对象的measureText或getTextBounds绘制的字符串的大小

请您举例说明。