我正在尝试像这样从 TextView 获取位图:
private Bitmap getBitmapFromView(View view) {
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
view.draw(canvas);
return returnedBitmap;
}
但是返回的位图包含带有不需要轮廓的 TextView 位图,请参阅 picture from Android Studio Debugger .我也尝试使用相同的函数,但在 ImageView 上应用了返回位图,但它没有这样的轮廓。我不明白如何解决这个问题。更新。
我的 TextView 布局:
<TextView
android:id="@+id/bitmaptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@android:color/transparent"
android:textColor="@color/white"
android:textSize="18sp"
tools:text="test"
tools:textColor="@color/white" />
UPD2。 这是示例项目:https://github.com/khoben/test-android , bitmap 本身有轮廓,但在 ImageView 中没有。我需要一个没有这个轮廓的图像。
UPD3 .我想在视频上从 texview 绘制位图,但是 outlining ruins all plans (pic) .
UPD4 .我应该说问题出现在来自
getBitmapFromView()
的图像时通过 OpenGL 在视频上绘制,原因是不正确的混合模式。 Link to detailed answer .
最佳答案
传递您的 TextView 在“ getBitmapFromView ”中。
public static Bitmap getBitmapFromView(View view) {
view.setDrawingCacheEnabled(true);
Bitmap returnedBitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
return returnedBitmap;
}
关于android - 不需要的 textview 的位图轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65359374/