读取图片字节流 - GetImageData
函数简介
获取指定图像的二进制数据,数据格式BBGGRRAA(BGRA),每个像素4字节。
接口名称
GetImageData
DLL调用
int GetImageData(long ola, long ptr, long* data, int* size, int* stride);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| ptr | 长整数型 | OLAImage对象的地址 |
| data | 长整数型指针 | 返回图片的数据指针 |
| size | 整数型指针 | 返回图片的数据长度 |
| stride | 整数型指针 | 返回图片的步长数据(每行数据字节数) |
示例
C++
long instance = CreateCOLAPlugInterFace();
// hwnd 为绑定的窗口句柄
long img = GetScreenDataPtr(instance, 0, 0, 0, 0);
long data = 0;
int size = 0, stride = 0;
int ret = GetImageData(instance, img, &data, &size, &stride);
if (ret == 1) {
int width = stride / 4;
int height = size / stride;
printf("图像: %dx%d, BGRA数据大小: %d\n", width, height, size);
// 注意:释放img后data也会失效,需先拷贝数据
}
FreeImagePtr(instance, img);
Python
# 待补充
返回值
整数型:1 成功,0 失败。
注意事项
- 图像指针释放后(FreeImagePtr),data地址的数据就会被释放,需要把数据拷贝到自己的字节集中再使用。
- 图像宽度 = stride / 4,图像高度 = size / stride。
