image.createPixelMapFromSurface报62980178 HarmonyOS 鸿蒙Next

image.createPixelMapFromSurface报62980178 HarmonyOS 鸿蒙Next 我使用XComponent的宽高会报62980178,为什么?

this.surfaceWidth = this.mXComponentController.getXComponentSurfaceRect().surfaceWidth;
this.surfaceHeight = this.mXComponentController.getXComponentSurfaceRect().surfaceHeight;

上面的代码运行后直接报错,但是我改小宽高后,又能正常截取图片了,究竟这个宽高是怎么获取的

let region: image.Region = { x: 0, y: 0, size: { height: this.surfaceHeight, width: this.surfaceWidth } };
image.createPixelMapFromSurface(surfaceId, region).then((pixelMap) => {
  console.info('Succeeded in creating pixelmap from Surface');
  pixelMap.rotateSync(90);
}).catch((error: BusinessError) => {
  console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`);
});
let region: image.Region = { x: 0, y: 0, size: { height: 1900, width: 1000 } };
image.createPixelMapFromSurface(surfaceId, region).then((pixelMap) => {
  console.info('Succeeded in creating pixelmap from Surface');
  pixelMap.rotateSync(90);
}).catch((error: BusinessError) => {
  console.error(`Failed to create pixelmap. code is ${error.code}, message is ${error.message}`);
});

更多关于image.createPixelMapFromSurface报62980178 HarmonyOS 鸿蒙Next的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

region参数中的宽高不是XComponent的宽高,是预览流的宽高,可参照该问题理解:https://developer.huawei.com/consumer/cn/doc/architecture-guides/develop-medium-6-0000002069456958

更多关于image.createPixelMapFromSurface报62980178 HarmonyOS 鸿蒙Next的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


`image.createPixelMapFromSurface`报错62980178通常与鸿蒙Next系统中的图像处理模块相关。该错误可能由以下原因导致:

1. Surface无效:传入的`Surface`对象可能为空或已释放,导致无法创建`PixelMap`。
2. 资源不足:系统内存或图形资源不足,无法完成图像处理操作。
3. 权限问题:应用可能缺少必要的权限,如访问相机或存储的权限。
4. API调用错误:`createPixelMapFromSurface`的参数或调用方式不符合鸿蒙Next的API规范。

检查`Surface`对象的状态、系统资源、应用权限以及API调用方式,通常可以定位并解决该问题。
回到顶部