将文本添加到图像中,并共享为img文件android



我正在尝试制作一个类似HBD愿望共享应用程序的应用程序,但我想将文本添加到图像中,并将其作为图像文件共享。在相对布局中添加图像中的文本很简单,但我想将该图像和文本作为图像文件共享。我的应用程序可能看起来像一个证书生成器(例如sololearn应用程序(

Thank You

只需在此处传递相对布局的id,它将返回整个视图的位图。然后,您可以将其保存为PNG文件,这样就可以开始了。

private Bitmap getBitmapFromView(View view) {
view.setDrawingCacheEnabled(true);
Bitmap returnedBitmap = view.getDrawingCache();
Canvas canvas = new Canvas(returnedBitmap);
Drawable bgDrawable =view.getBackground();
if (bgDrawable!=null) {
bgDrawable.draw(canvas);
}   else{
canvas.drawColor(Color.WHITE);
}
view.draw(canvas);
return returnedBitmap;
}

最新更新