图像侦听器无法从片段中选择图像(Image Listener unable to pick image from the fragment)

编程入门 行业动态 更新时间:2024-10-21 13:32:00
图像侦听器无法从片段中选择图像(Image Listener unable to pick image from the fragment)

图像可用的侦听器拾取片段的图像,并且一旦图像可用,就会连续调用onimageavailble() 。 代码实例如下:

protected void onCreate(final Bundle savedInstanceState) { super.onCreate(null); getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_camera); setFragment(); }

setFragment()代码是:

protected void setFragment() { final Fragment fragment = CameraConnectionFragment.newInstance( new CameraConnectionFragment.ConnectionCallback() { @Override public void onPreviewSizeChosen(final Size size, final int rotation) { CameraActivity.this.onPreviewSizeChosen(size, rotation); } }, this, getLayoutId(), getDesiredPreviewFrameSize()); getFragmentManager() .beginTransaction() .replace(R.id.container, fragment) .commit(); }

代码在Android上正确运行,因此我希望它在Android Things设备上实现,但我收到一条警告,指出' 一个TextureView或一个子类只能用于启用硬件加速 ',并且永远不会调用onimageavailble() 。 我在代码中进行了必要的更改以解决警告,但仍然没有调用onimageavailble() 。

在调试用于android事物的raspberry Pi3中的代码时,我注意到片段中没有显示相机流,因为图像侦听器无法选择一个。

请为我提供这个问题的解决方案

Image available listener picks up an image of the fragment and onimageavailble() is invoked continuously as soon as the image is available. An instance of the code is as below:

protected void onCreate(final Bundle savedInstanceState) { super.onCreate(null); getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_camera); setFragment(); }

The setFragment() code is:

protected void setFragment() { final Fragment fragment = CameraConnectionFragment.newInstance( new CameraConnectionFragment.ConnectionCallback() { @Override public void onPreviewSizeChosen(final Size size, final int rotation) { CameraActivity.this.onPreviewSizeChosen(size, rotation); } }, this, getLayoutId(), getDesiredPreviewFrameSize()); getFragmentManager() .beginTransaction() .replace(R.id.container, fragment) .commit(); }

The code runs correctly on Android and so I wanted it to implement on Android Things device but I was getting a warning stating 'A TextureView or a subclass can only be used with hardware acceleration enabled' and the onimageavailble() is never called. I made required changes in the code to resolve the warning but still, onimageavailble() is never called.

On debugging the code in raspberry Pi3 for android things, I noticed that camera stream is not being displayed in the fragment because of which image listener is unable to pick one.

please provide me with the solution for this problem

最满意答案

您正在使用WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED (使用AndroidThings 0.3.0 )

R Pi的硬件​​加速仅在AndroidThings 0.5.0引入

请参阅此处的发行说明:

https://developer.android.com/things/preview/releases.html

随着Android O的更新,现在支持OpenGL ES 2.0。 带GPU的平台(如Raspberry Pi 3)现在也支持硬件加速。

请更新您正在使用的AndroidThings版本。

You are using WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED (with AndroidThings 0.3.0)

Hardware Acceleration for the R Pi was only introduced in AndroidThings 0.5.0

See the release notes here:

https://developer.android.com/things/preview/releases.html

With the update to Android O, OpenGL ES 2.0 is now supported. Platforms with a GPU (such as Raspberry Pi 3) also now support hardware acceleration.

Please update the version of AndroidThings you are using.

更多推荐

onimageavailble,fragment,代码,code,电脑培训,计算机培训,IT培训"/> <meta name=&q

本文发布于:2023-08-01 17:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1361524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:侦听器   图像   片段   Image   Listener

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!