gpt4 book ai didi

android - Canvas.drawTextOnPath(...) 不适用于 Lollipop

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:58:16 27 4
gpt4 key购买 nike

canvas.DrawTextOnPath 似乎不适用于 Lollipop 设备。看看这里的区别。 (连结 10图片正确,但 Lollipop 显示不正确)

Image

代码是一个简单的路径绘制。

// Path for the inner circle
unitPath = new Path();
unitPath.addArc(unitRect, 180.0f, 180.0f);

// Draw the text and the path
canvas.drawTextOnPath("Inner Circle", unitPath, 0.0f, 0.0f, unitPaint);
canvas.drawPath(unitPath,unitPaint);

任何想看的人都可以在这里看到说明这个问题的 Android Studio 测试项目。 https://dl.dropboxusercontent.com/u/6768304/WebLinks/TestApp.rar

我需要在此设备上做一些“不同”的事情吗?

最佳答案

好的,看起来 DrawTextOnPath 现在有点破损,字体大小低于 1.0f

解决方案是放大所有内容,绘制文本然后将其缩小。

演示项目中的 drawTitle 方法将更改为:

private void drawTitle(Canvas canvas) {
canvas.drawTextOnPath(upperTitle, upperTitlePath, 0.0f, 0.02f, unitPaint);
canvas.drawTextOnPath(lowerTitle, lowerTitlePath, 0.0f, 0.0f, unitPaint);
canvas.drawTextOnPath(unitTitle, unitPath, 0.0f, 0.0f, unitPaint);
canvas.drawPath(unitPath,unitPaint);
}

为此:

private void drawTitle(Canvas canvas) {
//Save original font size
float originalTextSize = unitPaint.getTextSize();

// set a magnification factor
final float magnifier = 100f;

// Scale the canvas
canvas.save();
canvas.scale(1f / magnifier, 1f / magnifier);

// create new rects and paths based on the new scale
unitRect = new RectF();
unitRect.set((faceRect.left + unitPosition) * magnifier, (faceRect.top + unitPosition) * magnifier, (faceRect.right - unitPosition) * magnifier, (faceRect.bottom - unitPosition) * magnifier);
unitPath = new Path();
unitPath.addArc(unitRect, 180.0f, 180.0f);

titleRect = new RectF();
titleRect.set((faceRect.left + titlePosition) * magnifier, (faceRect.top + titlePosition) * magnifier, (faceRect.right - titlePosition) * magnifier, (faceRect.bottom - titlePosition) * magnifier);
upperTitlePath = new Path();
upperTitlePath.addArc(titleRect, 180.0f, 180.0f);

titleRect = new RectF();
titleRect.set((faceRect.left + titlePosition) * magnifier, (faceRect.top + titlePosition) * magnifier, (faceRect.right - titlePosition) * magnifier, (faceRect.bottom - titlePosition) * magnifier);
lowerTitlePath = new Path();
lowerTitlePath.addArc(titleRect, -180.0f, -180.0f);

// increase the font size
unitPaint.setTextSize(originalTextSize * magnifier);

// do the drawing of the text
canvas.drawTextOnPath(unitTitle, unitPath, 0.0f, 0.0f, unitPaint);
canvas.drawTextOnPath(upperTitle, upperTitlePath, 0.0f, 0.02f, unitPaint);
canvas.drawTextOnPath(lowerTitle, lowerTitlePath, 0.0f, 0.0f, unitPaint);

// bring everything back to normal
canvas.restore();
unitPaint.setTextSize(originalTextSize);

canvas.drawPath(unitPath, unitPaint);
}

关于android - Canvas.drawTextOnPath(...) 不适用于 Lollipop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26738608/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com