JavaScript图像未在QML中定义
我想在QML文件(QT 5.11)中使用new Image()
。 我使用导入...
避免QML图像与JS图像名称冲突。 但是现在,以下最小示例的结果错误是:
参考文献:未定义图像
import QtQuick 2.11 as QQ
QQ.Canvas {
width: 200
height: 200
onPaint: {
// this is the javascript part.
var img = new Image();
// ...
}
}
任何帮助都非常感谢以解决此问题。我是否需要在我的操作系统(Debian)上安装任何软件包才能正常工作?
I would like to use new Image()
in my QML file (Qt 5.11).
I use import ... as
to avoid QML Image vs JS Image name clash.
But now, the resulting error on the following minimal example is:
ReferenceError: Image is not defined
import QtQuick 2.11 as QQ
QQ.Canvas {
width: 200
height: 200
onPaint: {
// this is the javascript part.
var img = new Image();
// ...
}
}
Any help is greatly appreciated to solve this. Do I need to install any packages on my OS (debian) for this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要在
canvas
中绘制图像,则需要使用loadImage()
。它将异步加载,画布将在加载任何新图像后发出ImageLoaded
。然后,您可以用代码> 并将其传递给您加载的URL:
If you want to paint an image in a
Canvas
you need to useloadImage()
. It will be loaded asynchronously and the canvas will emitimageLoaded
when any new image has loaded.You can then paint it with
drawImage()
and passing it the URL you loaded: