海洋如何将获取到的图像放置到 Image 组件中
8个贝壳InputStream inputStream = connection.getInputStream();
ImageSource imageSource = ImageSource.create(inputStream,null);
PixelMap pixelMap = imageSource.createPixelmap(null);
this.getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
if (pixelMap!=null){
networkImg.setPixelMap(pixelMap);
networkImg.setPixelMap(ResourceTable.Media_icon);
}
textInfo.setText("网络图片加载成功");
}
});
inputStream.close();
}
chaoxiaoshu
先获取图片的字节输入流
https://developer.harmonyos.com/cn/docs/documentation/doc-guides/connectivity-net-url-0000000000045542
写入字节输出流
try (InputStream inputStream = response.getInputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();){ while ((len = inputStream.read(bytes)) != -1) { outputStream.write(bytes, 0, len); }eventHandler.sendEvent(InnerEvent.get(1001, outputStream.toByteArray()));}catch (IOException e) {}
Byte数组转PixelMap
EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner()) { @Override protected void processEvent(InnerEvent event) { super.processEvent(event); if (event == null) { return; } if (event.eventId == 1001) { byte[] bytes = (byte[]) event.object; ImageSource imageSource = ImageSource.create(bytes, null); PixelMap pixelmap = imageSource.createPixelmap(null); image.setPixelMap(pixelmap); pixelmap.release(); } } };
五维空间幻影猫

- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要发帖子
HarmonyOS 如何在自定义组件外部监听组件的aboutToAppear和aboutToDisappear(API12+)
HarmonyOS imageComponent的byteBuffer长度为什么比预期多2048字节 (API12+)
HarmonyOS wrapperBuilder传递map时会丢失,到目标组件的时候,会变成undifined,换成其他的类型就没这个问题 (API12+)
HarmonyOS 容器组件大小固定,如何根据文本内容大小的计算结果(MeasureText),动态调整布局(API17+)
HarmonyOS Tabs组件tabBar如何实现从左到右,从上到下?(API12+)
HarmonyOS 表格使用Grid组件渲染时,高度不自适应怎么解决?(API12+)
HarmonyOS grid组件中,监听它的拖拽事件,拖到底部的时候概率出现onDragEnter没有触发的情况,导致无法滑动 (API12+)
HarmonyOS 组件出现在鼠标位置时,不会触发onHover (API12+)




































苏公安网备 32011402010933号