Android-在不同位置的画布上绘制图像和文字



我想在画布上绘制一些文字和图像,模板将是这样的东西

我设法绘制了文本,但我坚持绘制图像。

这是我所做的

Bitmap bmp = Bitmap.createBitmap(949, 300, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmp);
        TextPaint tp = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        tp.setColor(0xFF000000);
        tp.setTextSize(15 * getApplicationContext().getResources().getDisplayMetrics().density + 0.5f);
        tp.setShadowLayer(2, 0.5f, 0.5f, Color.BLACK);
        StaticLayout sl = new StaticLayout("This is",
                tp, 300, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false);
        StaticLayout sm = new StaticLayout("This is",
                tp, 300, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false);

        canvas.save();
        canvas.translate(50, 20); //position text on the canvas
        sl.draw(canvas);
        canvas.restore();
        canvas.save();
        canvas.translate(50, 90); //position text on the canvas
        sm.draw(canvas);
        canvas.restore();
        ImageView iv = (ImageView) findViewById(R.id.iv);
        iv.setImageBitmap(bmp);

<ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/border_ui" />

任何想法如何绘制图像?

ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setImageBitmap(bmp);
iv.draw(canvas); // Pass canvas to view to draw

最新更新