在图像上写入文本并将图像保存在SD卡中,而不在屏幕上绘制

Rah*_*ani 2 android canvas view bitmap android-custom-view

我已经在很长一段时间里一直在努力解决这个问题.我想从资源文件夹中获取一个图像并编写一些文本,作为一个过程的一部分动态生成,然后将最终图像与文本保存在SD卡中.我知道如何在SD卡中写入文件.我无法在图像上写下文字.

我创建了一个带有imageview和textview的RelativeLayout并将其保存到SD卡但后来意识到我不必绘制视图.所以,不能用这个.

同样,我想强调一点,即我的应用程序不需要在当前屏幕上绘制位图.

有人可以提供任何解决方案吗?

谢谢!:)

Ric*_*ard 6

不要使用图像视图.

使用帆布!

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);
Bitmap alteredBitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig());
Canvas canvas = new Canvas(alteredBitmap);
Paint paint = new Paint();
canvas.drawBitmap(bm, 0, 0, paint);
paint.setColor(Color.BLACK); 
paint.setTextSize(20); 
canvas.drawText("Some Text", 10, 25, paint); 
Run Code Online (Sandbox Code Playgroud)

然后将"changedBitmap"保存到SD卡