2021-11-18 16:38:35 +08:00
|
|
|
import {
|
|
|
|
Base64Resource,
|
|
|
|
DrawableResource,
|
|
|
|
Group,
|
|
|
|
Panel,
|
|
|
|
jsx,
|
|
|
|
Color,
|
|
|
|
layoutConfig,
|
|
|
|
Image,
|
|
|
|
RemoteResource,
|
|
|
|
MainBundleResource,
|
|
|
|
Scroller,
|
|
|
|
VLayout,
|
|
|
|
Text,
|
|
|
|
Gravity,
|
2021-11-18 19:06:10 +08:00
|
|
|
createRef,
|
|
|
|
loge,
|
2021-11-18 16:38:35 +08:00
|
|
|
} from "doric";
|
|
|
|
import { colors, label } from "./utils";
|
|
|
|
import { img_base64 } from "./image_base64";
|
|
|
|
|
|
|
|
@Entry
|
|
|
|
export class ResourceDemo extends Panel {
|
|
|
|
build(root: Group): void {
|
2021-11-18 19:06:10 +08:00
|
|
|
const iv = createRef<Image>();
|
2021-11-19 14:30:24 +08:00
|
|
|
async function click() {
|
|
|
|
const imageInfo = await iv.current.getImageInfo(context);
|
|
|
|
loge(imageInfo);
|
|
|
|
const pixels = await iv.current.getImagePixels(context);
|
|
|
|
loge(pixels.byteLength);
|
|
|
|
const data = new Uint8Array(pixels);
|
|
|
|
for (let i = 0; i < data.length - 4; i += 4) {
|
2021-11-22 17:54:23 +08:00
|
|
|
data[i + 3] = 0xff / 5;
|
2021-11-19 14:30:24 +08:00
|
|
|
}
|
|
|
|
iv.current.imagePixels = {
|
|
|
|
width: imageInfo.width,
|
|
|
|
height: imageInfo.height,
|
|
|
|
pixels: pixels,
|
|
|
|
};
|
|
|
|
}
|
2021-11-18 16:38:35 +08:00
|
|
|
<Scroller parent={root} layoutConfig={layoutConfig().most()}>
|
|
|
|
<VLayout
|
|
|
|
layoutConfig={layoutConfig().mostWidth().fitHeight()}
|
|
|
|
space={10}
|
|
|
|
gravity={Gravity.Center}
|
|
|
|
>
|
|
|
|
<Text
|
|
|
|
layoutConfig={layoutConfig().mostWidth().justHeight()}
|
|
|
|
textSize={30}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
backgroundColor={colors[5]}
|
|
|
|
textAlignment={Gravity.Center}
|
|
|
|
height={50}
|
|
|
|
>
|
2021-11-19 14:30:24 +08:00
|
|
|
Resource Demo
|
2021-11-18 16:38:35 +08:00
|
|
|
</Text>
|
|
|
|
{label("Button")}
|
|
|
|
<Image
|
|
|
|
image={
|
|
|
|
Environment.platform === "Android"
|
|
|
|
? new DrawableResource("doric_icon_back")
|
|
|
|
: new MainBundleResource("Hanabi.ttf")
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Image
|
2021-11-22 17:54:23 +08:00
|
|
|
ref={iv}
|
2021-11-18 16:38:35 +08:00
|
|
|
image={
|
|
|
|
new RemoteResource("https://p.upyun.com/demo/webp/webp/jpg-0.webp")
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
image={new Base64Resource(img_base64[0])}
|
|
|
|
onClick={async () => {
|
2021-11-19 14:30:24 +08:00
|
|
|
await click();
|
2021-11-18 16:38:35 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</VLayout>
|
|
|
|
</Scroller>;
|
|
|
|
}
|
|
|
|
}
|