feat:android support ArrayBuffer Resource

This commit is contained in:
pengfei.zhou
2021-11-18 19:06:10 +08:00
committed by osborn
parent 3bedd8034c
commit e270b9c520
21 changed files with 481 additions and 59 deletions

View File

@@ -19,26 +19,19 @@ import { BridgeContext } from "../runtime/global"
export function imageDecoder(context: BridgeContext) {
return {
decode: async (resource: Resource) => {
await context.callNative('imageDecoder', 'loadResource', resource);
const imageInfo = await context.callNative(
getImageInfo: (resource: Resource) => {
return context.callNative(
'imageDecoder',
'getImageInfo',
resource.resId) as Promise<
resource) as Promise<
{
width: number,
height: number,
format: string,
mimeType: string,
}>;
const pixels = await context.callNative(
'imageDecoder',
'decodeToPixels',
resource.resId) as Promise<ArrayBuffer>;
await context.callNative('imageDecoder', 'releaseResource', resource.resId);
return {
...imageInfo,
pixels,
};
},
decodeToPixels: async (resource: Resource) => {
return context.callNative('imageDecoder', 'decodeToPixels', resource) as Promise<ArrayBuffer>;
},
}
}

View File

@@ -25,4 +25,5 @@ export * from './statusbar'
export * from './coordinator'
export * from './notch'
export * from './keyboard'
export * from './resourceLoader'
export * from './resourceLoader'
export * from './imageDecoder'

View File

@@ -82,4 +82,11 @@ export class BundleResource extends iOSResource {
constructor(bundleName: string, fileName: string) {
super("bundle", `${bundleName}://${fileName}`)
}
}
export class ArrayBufferResource extends Resource {
constructor(data: ArrayBuffer) {
super("arrayBuffer", "")
}
}