我想drawTextToBitmap在位图图像上添加一个字符串。我有一个方法,这种方法在位图图像上工作成功将字符串放置在位图图像上。但我的位图图像非常小,像针标记图像。此函数根据位图高度和宽度设置字符串。我想放置字符串超过位图图像。所以请帮我解决问题。
我用来获取位图的以下方法:
public Bitmap drawTextToBitmap(Context gContext, int gResId, String gText) {
Resources resources = gContext.getResources();
float scale = resources.getDisplayMetrics().density;
Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId);
android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
// set default bitmap config if none
if (bitmapConfig == null) {
bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
}
// resource bitmaps are imutable,
// so we need to convert it to mutable one
bitmap = bitmap.copy(bitmapConfig, true);
Canvas canvas = new Canvas(bitmap);
// new antialised Paint
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
// …Run Code Online (Sandbox Code Playgroud)