在Android应用中拍摄Unity场景的屏幕截图

我的Android应用程序中有一个Unity场景作为视图的一部分。从Unity编辑器导出项目后,这就是我的设置方式。

protected void onCreate(Bundle savedInstanceState) {
    this.getWindow().clearflags(WindowManager.LayoutParams.flaG_FULLSCREEN);

    super.onCreate(savedInstanceState);
    mUnityPlayer = new UnityPlayer(this);
    binding = DataBindingUtil.setContentView(this,R.layout.main);

    mUnityPlayer.setBackgroundResource(R.drawable.some_drawable);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
    binding.scene.addView(mUnityPlayer.getView(),lp);
}

这很好。现在,我需要获取该场景的屏幕截图,并在另一个ImageView中进行展示。问题在于UnityPlayer是FrameLayout,我希望对此使用getDrawingCache()来获取屏幕截图。

但这只会返回我的背景图像R.drawable.some_drawable,而Unity场景中的任何文本和其他信息都不会显示在屏幕截图中。我认为发生这种情况的原因可能是其他内容不是FrameLayout的一部分,而是呈现在某些TextureView上。我可能完全错了。但是我无法弄清楚如何以Bitmap的形式来获取场景内内容的屏幕快照,我可以将其设置在另一个imageView上。

任何指针或帮助将不胜感激。谢谢!

xin34140 回答:在Android应用中拍摄Unity场景的屏幕截图

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3138747.html

大家都在问