【发布时间】:2015-12-30 09:03:55
【问题描述】:
我创建了一个函数来在路径上绘制文本:
public void drawText(float x, float y, String text) {
Log.i("DRAWING", "drawText");Typeface.BOLD);
mPath.reset();
mPath.moveTo(x, y);
mPath.lineTo(x+200,y);
Paint textPaint = new Paint();
textPaint.setColor(Color.RED);
textPaint.setTextSize(20f);
textPaint.setAntiAlias(true);
textPaint.setStrokeWidth(5f);
textPaint.setStyle(Paint.Style.FILL);
mCanvas.drawTextOnPath(text, mPath, 0, 0, textPaint);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
paths.add(mPath);
invalidate();
}
我这样设置Bitmap:
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas();
mCanvas.setBitmap(mBitmap);
reset();
}
问题:
当我设置位图时,它工作正常并且文本出现在ImageView 上,但是当我不设置时,只出现一条白线而不是文本。
我是否必须使用 Bitmap 在带有 drawTextOnPath 的路径上绘制文本?因为我只想使用路径(除了文本,一切都很好,就像它需要一个Bitmap)。
【问题讨论】:
-
看来你的问题已经包含了它的答案...
When I set a bitmap, it works fine and the text appears on the ImageView, but when I don't, just a white line appears and not the text. Do I have to use a Bitmap to draw text on path with drawTextOnPath ? -
@FrankN.Stein 好的,那为什么我不使用 Bitmap 时没有出现文字?
-
ImageView 是一个位图容器。您必须使用位图来提供它。
-
@FrankN.Stein 所以你是说位图是绘制文本而不是绘制路径所必需的?所以,不可能在路径中存储文本?
-
store text in paths? 你的意思是按照文本大纲创建路径吗?也许,但这将是一个矫枉过正。你对位图有什么看法?
标签: android text bitmap path draw