表情符号不随画布旋转 [英] emojis not rotating with canvas

查看:219
本文介绍了表情符号不随画布旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个允许用户使用文本绘制的应用程序,包括表情符号。用户可以根据自己的喜好旋转文本并调整其大小。当用户旋转包含表情符号的文本时,会发生此问题。

I have created an applications that allows users to paint with text, including emojis. The user can rotate and resize the text to their liking. The problem occurs when the user rotates text that includes emojis.

如您所见,存在不必要的重叠。我推断这是因为我画了两次文字来实现边框效果。有趣的是,如果文本大小超过一定数量,问题就解决了。这可以在最底层的测试中看到。

As you can see, there is unwanted overlap. I have deduced that this is because i draw the text twice to achieve a border affect. Whats interesting, is that the problem solves itself if the text size exceeds a certain amount. this can be seen in the bottom most test.

以下是绘制上述图像的代码:

Here is the code that drew the above image:

    public void draw(Canvas c, int x, int y) {

    Rect re = new Rect();
    Paint p = new Paint();
    p.setColor(this.color);
    p.setTextSize(this.GetSize());
    p.getTextBounds(text, 0, text.length(), re);
    p.setAntiAlias(true);

    c.save();
    c.rotate(rotation_deg, x, y);

    c.drawText(text, x - re.width() / 2, y + ((re.height() - re.bottom) - re.height() / 2), p);

    p.setStyle(Paint.Style.STROKE);
    p.setColor(color2);
    c.drawText(text, x - re.width() / 2, y + ((re.height() - re.bottom) - re.height() / 2), p);

    c.restore();
}

删除第一个绘制命令修复了表情符号问题,但后来我得到了文本笔划。

removing the first draw command fixes the emoji problem, but then i just get the text stroke.

如何旋转包含表情符号的文本?

How can i rotate text that includes emojis?

一种可能的解决方案是绘制到首先是位图,然后旋转位图,但这个过程会浪费ram和time。

One possible solution is to draw to a bitmap first, and then rotate the bitmap, but this process would waste both ram and time.

推荐答案

既然你知道如何解决这个问题我会调查使用 Paint.setShadowLayer(float radius,float dx,float dy,int shadowColor) 而不是两次绘制文本。

Since you know how to solve the problem I would investigate using Paint.setShadowLayer(float radius, float dx, float dy, int shadowColor) and not drawing the text twice.


public void setShadowLayer(float radius,float dx,float dy,int shadowColor)

这会在主图层下面绘制一个阴影图层,指定的偏移量和颜色以及模糊半径。如果radius为0,则删除阴影层。

This draws a shadow layer below the main layer, with the specified offset and color, and blur radius. If radius is 0, then the shadow layer is removed.

可用于在文本下方创建模糊阴影。支持与其他绘图操作一起使用仅限于软件渲染管道。

Can be used to create a blurred shadow underneath text. Support for use with other drawing operations is constrained to the software rendering pipeline.

如果阴影颜色不透明,则阴影的alpha值将为paint的alpha值,或alpha如果不是阴影颜色。

The alpha of the shadow will be the paint's alpha if the shadow color is opaque, or the alpha from the shadow color if not.



public void draw(Canvas c, int x, int y) {

    Rect re = new Rect();
    Paint p = new Paint();
    p.setColor(this.color);
    p.setTextSize(this.GetSize());
    p.getTextBounds(text, 0, text.length(), re);
    p.setAntiAlias(true);
    p. setShadowLayer (2.0f, 2.0f, -2.0f, this.color);

    c.save();
    c.rotate(rotation_deg, x, y);

    p.setStyle(Paint.Style.FILL_AND_STROKE);
    //p.setStyle(Paint.Style.FILL);

    p.setColor(color2);
    c.drawText(text, x - re.width() / 2, y + ((re.height() - re.bottom) - re.height() / 2), p);

    c.restore();
}

这篇关于表情符号不随画布旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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