如何获取带有表情符号的旋转TextView的屏幕截图? [英] How can i take screenshot of rotated TextView with emoji?

查看:147
本文介绍了如何获取带有表情符号的旋转TextView的屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作包含表情符号图标的旋转TextView的屏幕截图.但是在生成的位图上,我看到表情符号没有旋转!为什么会这样呢?如何使用旋转的表情符号制作屏幕截图?

I'm trying to make a screenshot of the rotated TextView which contain emoji icons. But on resulting bitmap i see that emoji are not rotated! Why is this happening? How can i make a screenshot with rotated emoji ?

我期望的是

这就是我得到的:

我正在使用此方法获取视图的屏幕截图:

I'm using this method to get screenshot of view:

layout.setDrawingCacheEnabled(true);
layout.buildDrawingCache();
Bitmap bitmap = null;
if (layout.getDrawingCache() != null)
    bitmap = layout.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
layout.setDrawingCacheEnabled(false);
layout.destroyDrawingCache();

更新: 正如我所想,如果我设置textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);,即使在TextView中表情符号也不会旋转(如果旋转TextView-它们不会旋转,它们只会像旋转木马一样旋转),但我仍然没有真正了解为什么会发生这种情况,或者表情符号旋转(在第一张图片上)仅是由于硬件加速引起的吗?

Update: as i figured, if I set textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); then emoji will not be rotated even in the TextView (if you rotate TextView - they will not be rotated, they will be just moving around like a carousel), but still I don't really understand why is this happening, or rotation of emoji (on first picture) is only because of hardware acceleration?

推荐答案

好的,我找不到解决这个令人讨厌的问题的方法,因此我不得不对其进行一点修改. imageviews可以完美地旋转. 所以我基本上使用图像视图进行所有操作-并使用此方法将图像设置为我想要的表情文字之外:

ok, i couldnt find a way to solve this really annoying issue, so i had to hack it a bit. imageviews works perfectly with rotation. so i basically do all the manipulations with image view - and setting it's image out of the emoji text i want using this method:

private Bitmap generateBitmapFromText(int size, String res) {
    TextView tv = new TextView(getContext());
    tv.setText(res);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, 150f);
    tv.setTextColor(0xffffffff);
    tv.measure(size, size);
    int questionWidth = tv.getMeasuredWidth();
    int questionHeight = tv.getMeasuredHeight();
    Bitmap bitmap = Bitmap.createBitmap(questionWidth, questionHeight, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    tv.layout(0, 0, questionWidth, questionHeight);
    tv.draw(c);
    return bitmap;
}

然后我打电话

    Bitmap bitmap = generateBitmapFromText(stickersStartingSize, res);
    imageview.setImageBitmap(bitmap);

这篇关于如何获取带有表情符号的旋转TextView的屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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