继成UVCCameraTextureView类,把一个图片传进去并显示
时间: 2023-11-28 14:50:03 浏览: 34
首先,我们需要在布局文件中定义一个 `UVCCameraTextureView` 控件,如下所示:
```xml
<com.serenegiant.usb.UVCCameraTextureView
android:id="@+id/texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
```
接下来,在代码中获取 `UVCCameraTextureView` 实例,并设置显示的图片:
```java
UVCCameraTextureView textureView = findViewById(R.id.texture_view);
// 加载图片
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sample_image);
// 将图片设置到 TextureView 中显示
textureView.setImageBitmap(bitmap);
```
如果需要在子线程中加载图片,可以使用 `Handler` 或者第三方库如 `Glide`、`Picasso` 等。以下是使用 `Glide` 加载图片并设置到 `UVCCameraTextureView` 上的示例代码:
```java
Handler mainHandler = new Handler(Looper.getMainLooper());
Glide.with(this)
.asBitmap()
.load(R.drawable.sample_image)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
mainHandler.post(() -> {
// 设置图片到 UVCCameraTextureView 中
textureView.setImageBitmap(resource);
});
}
});
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)