在路径上的Andr​​oid不必要的扭曲效果图文本 [英] Unwanted Warp effect drawing text on path android

查看:203
本文介绍了在路径上的Andr​​oid不必要的扭曲效果图文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的路径绘制文本的一些测试。我通过设置位图的帆布做了一个背景图片。然后,我绘制文本的路径,画布,由矩阵旋转。我不得不缩短code,我将只发布重要组成部分,因为它太long.This如下图所示的图像裁剪与瘸子,所以鸵鸟政策被激怒了不同的大小。我的矩形,路径和Matrix对象:

I do some tests on drawing text on path. I made a background picture by setting bitmap to canvas. Then, I draw text on path to canvas, rotated by matrix. I have to shorten the code, I will only post the important part, because it is too long.This images shown below are cropped with gimp, so don´t be irritated by the different sizes. My Rect,Path and Matrix objects:

    RectF drawTextOval;
    Path drawTextPath;
    Matrix mDrawnMatrix;

现在,这就是我的乐队画上圆圈路径文本:

Now, this is what I am doin to draw text on circle path:

    drawTextOval.set(drawTextPosX - drawTextArc, drawTextPosY
                    - drawTextArc, drawTextPosX + drawTextArc, drawTextPosY
                    + drawTextArc);
            drawTextPath.addArc(drawTextOval, 0, 360);

            drawTextPath.computeBounds(drawTextOval, true);
            mDrawnMatrix.postRotate(drawTextArcStart,
                    (drawTextOval.right + drawTextOval.left) / 2,
                    (drawTextOval.bottom + drawTextOval.top) / 2);
            drawTextPath.transform(mDrawnMatrix);

            patternCanvas.drawTextOnPath(drawText, drawTextPath, 0, 0,
                    mFixedTextPaint); 

直到此时,一切看起来不错:

Until this point, everything looks fine:

但保存整个屏幕之后,旋转的文字看起来扭曲在保存的PNG图片。所有其它部件看起来很不错。我做了一些其他的图形与文字,线性或角度,这一切工作。即使是一些巴纽位图绘图画布和背景图像......所有正在正常进行。但在圈内路径绘制的文字是这样的:

But after saving the whole screen, the rotated text looks warped at the saved .png image. All the other components looking good. I made some other drawings with text, linear or angular, all this works. Even some .png bitmaps drawing to canvas and the background image...all is looking normally. But the on circle path drawn text looks like this:

我不去做任何缩放的位图,只需节能与画布图像:

I don´t do any scaling on the bitmap, just saving the canvas image with:

    FileOutputStream fos = new FileOutputStream(saveFile);
        this.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
        Bitmap bitmap = this.getDrawingCache();


        bitmap.compress(CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();

为何文字看起来扭曲?有没有人看到我的错误?在此先感谢....

Why does the text look warped? Does anyone see my mistake? Thanks in advance....

我尝试了一些东西,找出设定anyDensity以虚假或禁用硬件加速清单将保存之前在运行时显示的效果。这表明,对我来说,节省了位图getDrawingCache(时),该比例在此时关闭。但是,为什么?

I tried some stuff and find out that setting anyDensity to false or disable hardware acceleration in Manifest will show the effect at runtime before saving. That suggests to me, that when saving bitmap with getDrawingCache(), the scaling is disabled at this time. But why?

最后我发现,该曲率越低,越低的文字缩放。如果文本只是一点点弯曲,看起来不错。

The last thing I found out, that the lower the curvature the lower is the text scaling. If the text is just a little bit curved, it seems good.

推荐答案

我会尝试设置

this.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

绘制到屏幕上,因为较低的质量可能意味着该文本的简单变换之前。这仅仅是猜测,当然。目前,您只设置了高品质写入磁盘之前。或者简单地将它从写入到磁盘的方法去除,以检查它是否影响绘制文本的方式。

before drawing to screen, since lower quality might imply a simpler transformation of the text. This is just guessing of course. Currently your only setting the high quality before writing to disk. Or simply remove it from the write to disk method to check if it affect the way the text is drawn.

这篇关于在路径上的Andr​​oid不必要的扭曲效果图文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆