Skip to content

Commit 9a80b6b

Browse files
author
ellie
committed
fix: 插入话题@文本高度
1 parent bd94bea commit 9a80b6b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

android/src/main/java/com/variabletextinput/util/BitmapUtil.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import android.graphics.Typeface;
99

1010
public class BitmapUtil {
11+
private static int height = 60;
12+
private static int baseLine = 48;
1113

1214
public static Bitmap getTextBitmap(String name, Typeface typeface, float fontSize, int color) {
1315
Paint paint = new Paint();
@@ -24,9 +26,9 @@ public static Bitmap getTextBitmap(String name, Typeface typeface, float fontSiz
2426
paint.getTextBounds(name, 0, name.length(), rect);
2527
// 获取字符串在屏幕上的长度
2628
int width = (int) (paint.measureText(name));
27-
final Bitmap bmp = Bitmap.createBitmap(width, rect.height(), Bitmap.Config.ARGB_8888);
29+
final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2830
Canvas canvas = new Canvas(bmp);
29-
canvas.drawText(name, rect.left, rect.height() - rect.bottom, paint);
31+
canvas.drawText(name, rect.left, baseLine, paint);
3032
return bmp;
3133
}
3234

@@ -39,4 +41,14 @@ public static Bitmap setBitmapSize(Bitmap bitmap, float size) {
3941
matrix.postScale(scaleWidth, scaleHeight);
4042
return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
4143
}
44+
45+
// private static int getBaseLine(Paint paint) {
46+
// if (baseLine == 0) {
47+
// Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
48+
// int dy = (fontMetrics.bottom - fontMetrics.top) / 2 - fontMetrics.bottom;
49+
// baseLine = dy;
50+
// return height / 2 + dy;
51+
// }
52+
// return baseLine;
53+
// }
4254
}

0 commit comments

Comments
 (0)