已合并
memory name #160986
zhangjianyu21创建于 8月14日
memory name #160986
已合并
共 1 个文件变更+64-0
| @@ -400,3 +400,67 @@ async function Release(receiver : image.ImageReceiver) { | |||
| 400 | }) | 400 | }) |
| 401 | } | 401 | } |
| 402 | ``` | 402 | ``` |
| 403 | + | ||
| 404 | +## setMemoryName | ||
| 405 | + | ||
| 406 | +setMemoryName(name: string): void | ||
| 407 | + | ||
| 408 | +为ImageReceiver接收的图像缓冲区设置内存标识符,便于在内存调试或问题定位时识别相关缓冲区。建议在注册[on](#on9)回调,以及调用[readNextImage](#readnextimage9)或[readLatestImage](#readlatestimage9)读取图像前进行设置。 | ||
| 409 | + | ||
| 410 | +> **说明:** | ||
7 | |||
| 411 | +> | ||
| 412 | +> - 为确保传入值与实际生效的内存标识符一致,请按照以下规则设置`name`: | ||
| 413 | +> | ||
| 414 | +> - 仅使用可见ASCII字符(0x21~0x7E),不要包含空格、换行符、制表符或其他控制字符。 | ||
| 415 | +> - 名称长度为1~255字节。 | ||
| 416 | +> - 当名称仅由数字组成时,接口会自动在名称前添加前缀`ImageReceiver:`。添加前缀后的内存标识符总长度不能超过255字节,即纯数字名称最长为241字节。 | ||
| 417 | +> | ||
| 418 | +> - 若希望传入值与实际生效的内存标识符完全一致,建议名称中至少包含一个非数字字符。 | ||
| 419 | + | ||
| 420 | +**起始版本:** 26.1.0 | ||
| 421 | + | ||
d.ts有模型约束,资料里也要写上 ![]() ![]() | |||
| 422 | +**模型约束:** 此接口仅可在Stage模型下使用。 | ||
| 423 | + | ||
| 424 | +**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver | ||
| 425 | + | ||
| 426 | +**参数:** | ||
| 427 | + | ||
| 428 | +| 参数名 | 类型 | 必填 | 说明 | | ||
| 429 | +| ------ | ------ | ---- | ---- | | ||
| 430 | +| name | string | 是 | ImageReceiver接收的图像缓冲区的内存标识符。请使用可见ASCII字符(0x21~0x7E),长度为1~255字节。当名称仅由数字组成时,接口会自动添加前缀`ImageReceiver:`;添加后的内存标识符总长度不能超过255字节,即纯数字名称最长为241字节。 | | ||
| 431 | + | ||
| 432 | +**错误码:** | ||
| 433 | + | ||
| 434 | +以下错误码的详细介绍请参见[Image错误码](errorcode-image.md)。 | ||
| 435 | + | ||
| 436 | +| 错误码ID | 错误信息 | | ||
| 437 | +| -------- | -------- | | ||
| 438 | +| 7900201 | Invalid parameter. Possible causes:<br>Name is empty.<br>Name contains no visible characters after filtering.<br>The length of name exceeds 256 bytes.<br>Ensure the name parameter contains visible ASCII characters. | | ||
| 439 | + | ||
| 440 | +**示例:** | ||
| 441 | + | ||
| 442 | +```ts | ||
| 443 | +import { BusinessError } from '@kit.BasicServicesKit'; | ||
| 444 | + | ||
| 445 | +function setMemoryNameSync(receiver: image.ImageReceiver) { | ||
| 446 | + try { | ||
| 447 | + // 建议在注册imageArrival回调并读取图片前设置内存标识符。 | ||
| 448 | + receiver.setMemoryName('ImageReceiverNameTest'); | ||
| 449 | + console.info('Succeeded in setting memory name.'); | ||
| 450 | + } catch (e) { | ||
| 451 | + const err = e as BusinessError; | ||
| 452 | + console.error(`Failed to set memory name. Code: ${err.code}, message: ${err.message}`); | ||
| 453 | + return; | ||
| 454 | + } | ||
| 455 | + | ||
| 456 | + receiver.on('imageArrival', () => { | ||
| 457 | + receiver.readNextImage().then((nextImage: image.Image) => { | ||
| 458 | + console.info('Succeeded in reading the next Image.'); | ||
| 459 | + // 处理图片数据。 | ||
| 460 | + nextImage.release(); | ||
| 461 | + }).catch((error: BusinessError) => { | ||
| 462 | + console.error(`Failed to read the next Image. Code: ${error.code}, message: ${error.message}`); | ||
| 463 | + }); | ||
| 464 | + }); | ||
| 465 | +} | ||
| 466 | +``` | ||


这个接口是说设置标识符。 下面的说的过滤是指不允许这样设置,还是说只是最后其他地方调用的时候会满足这三个条件。