Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 表情符号不随画布旋转_Java_Android_Drawing_Android Canvas - Fatal编程技术网

Java 表情符号不随画布旋转

Java 表情符号不随画布旋转,java,android,drawing,android-canvas,Java,Android,Drawing,Android Canvas,我创建了一个应用程序,允许用户使用文本进行绘制,包括表情符号。用户可以根据自己的喜好旋转和调整文本大小。当用户旋转包含表情符号的文本时会出现问题。 如您所见,存在不必要的重叠。我推断这是因为我绘制了两次文本以实现边界效果。有趣的是,如果文本大小超过一定数量,问题就会自行解决。这可以在最下面的测试中看到 以下是绘制上图的代码: public void draw(Canvas c, int x, int y) { Rect re = new Rect(); Paint p

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

如您所见,存在不必要的重叠。我推断这是因为我绘制了两次文本以实现边界效果。有趣的是,如果文本大小超过一定数量,问题就会自行解决。这可以在最下面的测试中看到

以下是绘制上图的代码:

    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();
}
删除第一个draw命令修复了emoji问题,但是我只得到了文本笔划

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


一种可能的解决方案是先绘制位图,然后旋转位图,但此过程将浪费ram和时间

既然你知道如何解决这个问题,我将研究使用而不是两次绘制文本

public void setShadowLayer(浮点半径、浮点dx、浮点dy、int shadowColor)

这将在主层下方绘制一个阴影层,具有指定的偏移、颜色和模糊半径。如果“半径”为0,则将删除阴影层

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

如果阴影颜色不透明,则阴影的alpha将是绘制的alpha;如果阴影颜色不透明,则阴影的alpha将是绘制的alpha


我不知道如何在不浪费内存的情况下解决这个问题。我试图在画布上画一个有一定角度的边框的文本,就像这样。问题是,当我旋转文本时,表情符号不会旋转。我试着实现你建议的阴影层,但它也不起作用。。。表情符号仍然不随文本旋转。但阴影效果很酷!:)@篱笆骑手很奇怪。在最初的问题中,您提到如果删除了第一个“绘制”命令,问题就解决了。你是说你这么做了,添加了setShadowLayer调用,问题又出现了?不完全是。。。当我删除第一个绘制命令时,表情符号与文本对齐,但文本没有填充,只有一个边框。所以我尝试设置阴影并删除第一个draw命令,这导致表情符号对齐,但仍然没有填充。也许我设置的阴影是错误的,它只是导致文本周围有一个黑云是的
p.setStyle(Paint.Style.STROKE)
只提供了边框。尝试设置阴影并注释掉第一个绘制命令和
p.setStyle(Paint.Style.STROKE)
线条。@Fence\u rider或与其注释掉阴影,不如尝试将其更改为
Paint.Style.FILL和\u STROKE
Paint.Style.FILL
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();
}