如何在Dart中加载图像 [英] How to load an image in Dart

查看:77
本文介绍了如何在Dart中加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了Dart语言和HTML5 Canvas元素,但我遇到了一个问题。我不知道如何在Dart中加载图像。我可以得到CanvasRenderingContext2D和这个我可以调用fillText()和fillRect()和一切工作,但我想知道如何加载一个图像和绘制与drawImage。

I'm trying out the Dart Language and HTML5 Canvas element, but I'm stuck with one problem. I don't know how to load an image in Dart. I can get CanvasRenderingContext2D and with this I can call fillText() and fillRect() and everything works, but I am trying to figure out how to load an Image and draw with drawImage.

推荐答案

创建并加载图片

ImageElement image = new ImageElement(src: "my_image.png");
image.onLoad.listen((e) {
    // Draw once the image is loaded
});

在画布上绘制上述图片

context.drawImage(image, destX, destY);

这篇关于如何在Dart中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆