gpt4 book ai didi

android - 我如何截取带有表情符号的旋转 TextView 的屏幕截图?

转载 作者:行者123 更新时间:2023-11-29 01:20:14 27 4
gpt4 key购买 nike

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

我的期望:

enter image description here

这就是我得到的:

enter image description here

我正在使用此方法获取 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 - 它们不会旋转,它们会只是像旋转木马一样四处移动),但我仍然不明白为什么会这样,或者表情符号的旋转(在第一张图片上)只是因为硬件加速?

最佳答案

好吧,我找不到解决这个非常烦人的问题的方法,所以我不得不稍微修改一下。imageviews 与旋转完美配合。所以我基本上使用 ImageView 进行所有操作 - 并使用此方法将其图像设置为我想要的表情符号文本:

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);

关于android - 我如何截取带有表情符号的旋转 TextView 的屏幕截图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37254577/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com