error: no member named 'getWidth' in 'android::SurfaceControl' 对应的头文件
时间: 2023-07-29 22:09:33 浏览: 208
android::SurfaceControl 的头文件是 "android/view/SurfaceControl.h"。您需要在代码中包含这个头文件才能使用 SurfaceControl 的成员函数,包括 getWidth。可以尝试在代码中添加以下代码:
```c++
#include <android/view/SurfaceControl.h>
```
同时,您也需要确保您的开发环境中已经安装了 Android SDK 和 NDK,并且配置了正确的路径。
相关问题
android::SurfaceControl 获取宽高 demo
以下是一个获取 SurfaceControl 宽高的示例代码:
```c++
sp<SurfaceControl> surfaceControl;
int width = 0, height = 0;
// 获取 SurfaceControl 对象,这里假设已经获取到了
// ...
SurfaceComposerClient::Transaction transaction;
transaction.getTransformMatrix(surfaceControl->getHandle(), &matrix);
transaction.apply();
transaction.close();
Rect bounds;
surfaceControl->getBounds(&bounds);
width = bounds.getWidth();
height = bounds.getHeight();
// 现在变量 width 和 height 分别为 SurfaceControl 的宽度和高度
```
在示例代码中,我们首先获取了一个 SurfaceControl 对象(这里省略了获取过程),然后通过 `getBounds()` 方法获取了其边界矩形,再通过 `getWidth()` 和 `getHeight()` 方法获取宽度和高度。注意,这里的宽度和高度是以像素为单位的整数值。
在native层中,使用sp<SurfaceControl>SurfaceControl获取宽度和高度,以及对应的头文件
要在 native 层中使用 `sp<SurfaceControl>` 获取 SurfaceControl 的宽度和高度,可以使用 `SurfaceControl` 类的成员函数 `getWidth()` 和 `getHeight()`。同时,您需要包含以下头文件才能在 native 层中使用 SurfaceControl:
```c++
#include <gui/SurfaceControl.h>
#include <gui/Surface.h>
#include <android/native_window.h>
```
在您的代码中,您可以使用以下方式获取 SurfaceControl 的宽度和高度:
```c++
sp<SurfaceControl> surfaceControl;
int width, height;
// 获取 SurfaceControl 对象
surfaceControl = SurfaceControl::makeSurface(...);
// 获取 SurfaceControl 的宽度和高度
width = surfaceControl->getWidth();
height = surfaceControl->getHeight();
```
其中,`makeSurface(...)` 函数用于创建 SurfaceControl 对象,您需要根据您的具体需求填写参数。
阅读全文
相关推荐
















