安卓得到旋转,在画布上缩放文本边界 [英] Android get bounds of rotated,scaled text on canvas

查看:190
本文介绍了安卓得到旋转,在画布上缩放文本边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文字的TextView。 TextView中有触摸事件,让用户可以旋转​​,缩放和平移的文字。对于平移,旋转 和缩放我使用的画布。画布的OnDraw()函数中执行此操作。现在,我想有文本的外部边界,当它被缩放或旋转,任何人可以帮助我。 在此先感谢。

我尝试这片code到平移,旋转和帆布规模文字:

  canvas.scale(fScaledFactorForTextview,fScaledFactorForTextview,getTextWidth()/(2.0f * getLineCount())+ fTranslationX,(getTextSize()* getLineCount())/ 2.0f + fTranslationY) ;
canvas.rotate(fDegrees,getTextWidth()/(2.0f * getLineCount())+ fTranslationX,(getTextSize()* getLineCount())/ 2.0f + fTranslationY);
canvas.translate(fTranslationX,fTranslationY);
 

解决方案

在总体上是更容易,如果您使用的是矩阵,而不是直接旋转而像这种规模的呼叫做到这一点。如果您使用的是矩阵,你可以只是那些相同的调整应用到矩阵。然后你就可以很容易地转换任何时候正常笛卡尔通过由矩阵相乘的坐标坐标的改变坐标。矩阵甚至提供了mapPoints功能来做到这一点。

I have a textview with some text. Textview have touch events, so user can rotate, scale and translate text. For translation, rotation and scaling i'm using canvas. Canvas is doing this inside onDraw() function. Now i want to have outer bounds of text when it is scaled or rotated, can anybody help me. Thanks in Advance.

I try this piece of code to translate,rotate and scale text on canvas:

canvas.scale(fScaledFactorForTextview,fScaledFactorForTextview,getTextWidth() / (2.0f *   getLineCount()) + fTranslationX, (getTextSize() * getLineCount()) / 2.0f + fTranslationY);
canvas.rotate(fDegrees, getTextWidth() / (2.0f * getLineCount()) + fTranslationX,    (getTextSize() * getLineCount()) / 2.0f + fTranslationY);
canvas.translate(fTranslationX,fTranslationY);

解决方案

In general it's easier to do this if you use a matrix, rather than direct rotate and scale calls like this. If you use a matrix, you can just apply those same adjustments to the matrix. Then you can easily translate any point from normal Cartesion coordinates to the altered coordinates by multiplying the coordinates by that matrix. Matrix even provides the mapPoints function to do that.

这篇关于安卓得到旋转,在画布上缩放文本边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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