我一直在努力解决这个问题很长一段时间了。 我想从资源文件夹中获取一个图像并编写一些文本,作为一个过程的一部分动态生成,然后用SD卡中的文本保存最终图像。我知道如何编写文件在SD卡中。我无法在图像上写下文字。
我创建了一个带有imageview和textview的RelativeLayout并将其保存到SD卡但后来意识到我不必绘制视图。所以,不能这样做。
同样,我想强调一点,即我的应用程序不需要在当前屏幕上绘制位图。
有人可以提供任何解决方案吗?
谢谢! :)
答案 0 :(得分: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);
然后将'changedBitmap'保存到SD卡