类似的问题在stockoverflow上也有:
https://stackoverflow.com/questions/47807621/draw-emoji-on-bitmap-with-drawtextonpath
我的代码如下:
private Bitmap convertText2Bitmap(String text) {
if (TextUtils.isEmpty(text)) {
return null;
}
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.RED);
paint.setTextSize(sbTextSizeSP.getProgress());
paint.setDither(true);
paint.setFilterBitmap(true);
//测量text的宽高
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
Bitmap bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint.FontMetrics fontMetrics = paint.getFontMetrics();
float yPos = -fontMetrics.top;
canvas.drawText(text, 0, yPos, paint);
return bitmap;
}
大概在字体大于300px左右,bitmap上就没有emoji了。当字体小于300px是正常显示的。