fix(share): 截图改用 componentSnapshot 抓Web组件渲染像素(修WebGL黑屏) + 剪贴板图片改fd写入
- BridgeGameContainer: 大厅Web加 .id('web_lobby'),子游戏Web加 .id('web_subgame'),
供 componentSnapshot.get 按组件id定位
- WebSlot: captureCanvas 整体替换为 componentSnapshot.get + image.ImagePacker.packToData,
规避 WebGL canvas.toDataURL 黑屏;packToData 为 packing 的非废弃替代(§API13+);
删除 parseJsString(仅被旧 captureCanvas 内联用,新实现不需要)
- ShareProvider: writeClipboardImage 改用 fileIo.openSync 取 fd 再
createImageSource(fd),修复传路径字符串可能失败问题;补 import fileIo
API签名核对(devecocli docs):
componentSnapshot.get(id, options) → Promise<PixelMap>(deprecated API18,仍可用)
ImagePacker.packToData(pixelMap, PackingOption) → Promise<ArrayBuffer>(API13+,WARN无error)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
75b7c7fb07
commit
1902e4e5be
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
import { systemShare } from '@kit.ShareKit';
|
||||
import { uniformTypeDescriptor as utd } from '@kit.ArkData';
|
||||
import { fileUri } from '@kit.CoreFileKit';
|
||||
import { fileUri, fileIo } from '@kit.CoreFileKit';
|
||||
import { common, bundleManager } from '@kit.AbilityKit';
|
||||
import { BusinessError, pasteboard } from '@kit.BasicServicesKit';
|
||||
import { image } from '@kit.ImageKit';
|
||||
@@ -316,7 +316,14 @@ export class ShareProvider implements CapabilityProvider {
|
||||
|
||||
/** 图片写剪贴板(尽力;对方能否粘贴 PIXELMAP 不可保证,systemImage 才是可靠交付)。 */
|
||||
private writeClipboardImage(filePath: string): void {
|
||||
const source: image.ImageSource = image.createImageSource(filePath);
|
||||
let file: fileIo.File;
|
||||
try {
|
||||
file = fileIo.openSync(filePath, fileIo.OpenMode.READ_ONLY);
|
||||
} catch (e) {
|
||||
this.log.w(`clipboard image open failed: ${(e as Error).message}`);
|
||||
return;
|
||||
}
|
||||
const source: image.ImageSource = image.createImageSource(file.fd);
|
||||
source.createPixelMap().then((pm: image.PixelMap) => {
|
||||
let data: pasteboard.PasteData;
|
||||
try {
|
||||
@@ -326,14 +333,15 @@ export class ShareProvider implements CapabilityProvider {
|
||||
pm.release();
|
||||
return;
|
||||
}
|
||||
// pm 须存活到 setData 完成(createData 可能持引用),故在 setData settle 后再 release。
|
||||
pasteboard.getSystemPasteboard().setData(data)
|
||||
.then(() => this.log.i('clipboard image set ok'))
|
||||
.catch((e: BusinessError) => this.log.w(`clipboard image failed: ${e.code} ${e.message}`))
|
||||
.finally(() => pm.release());
|
||||
}).catch((e: BusinessError) => {
|
||||
this.log.w(`createPixelMap failed: ${e.code} ${e.message}`);
|
||||
}).finally(() => {
|
||||
source.release();
|
||||
fileIo.closeSync(file);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user