C
Qul::ImageProvider Struct
struct Qul::ImageProviderImageProvider 类提供了一个用于在 QML 中支持图像请求的接口。更多内容...
| Header: | #include <qul/imageprovider.h> |
| Since: | Qt Quick Ultralite 1.5 |
公共函数
| virtual Qul::SharedImage | requestImage(const char *uri, size_t uriLength) = 0 |
详细说明
ImageProvider 用于在 QML 应用程序中提供高级图像加载功能。
若要使用图像提供程序加载图像,请在图像的 URL 中使用“image:”方案,后跟图像提供程序的标识符和要请求的图像的标识符。例如:
Image { source: "image://myimageprovider/image.png" }这指定图像必须由名为“myimageprovider”的图像提供程序加载,且要加载的图像名为“image.png”。Qt Quick Ultralite 会根据通过 Qul::Application::addImageProvider() 注册的提供程序,调用相应的图像提供程序。
注意: 与QQuickImageProvider 不同,标识符 和 URL 的其余部分区分大小写。例如,上面的代码片段指定从名为“myimageprovider”的图像提供程序加载图像,而下面的代码片段则使用了名为“MyImageProvider”的图像提供程序。 此外,下面的示例请求了两张不同的图片(“Image.png”和“image.png”)。
Image { source: "image://MyImageProvider/image.png" }
Image { source: "image://MyImageProvider/Image.png" }另请参阅 Qul::Application::addImageProvider 。
成员函数文档
[pure virtual] Qul::SharedImage ImageProvider::requestImage(const char *uri, size_t uriLength)
实现此方法,以返回uri 和uriLength 对应的图像。
uri 是请求的图像源,其中已移除了“image://”方案和提供商标识符。例如,如果图像源为“image://myprovider/icons/home”,则给定的 URI 即为“icons/home”。
此函数可能会启动异步加载操作并返回一张未加载完成的图像。若要实现这一点,请在返回前调用Image::beginWrite(),并在加载完成后调用Image::endWrite()。
注意: Image::endWrite() 并非线程安全。请使用EventQueue 发送事件,并在事件处理程序中调用 endWrite()。
在某些 Qt 许可证下可用。
了解更多信息。