BB10 Cascades介绍之Image和ImageTracker

Image和ImageTracker

Image控件负责载入本地图片,包括资源图片和本地路径的图片,它必须是即刻得到且不会失败的。
// Absolute path
ImageView {
    imageSource: "asset:///images/myimage.png"  
}
 
// Relative path
ImageView {
    imageSource: "images/myimage.png"  
}


当然,如果外部图片在本地,可以即刻得到,也可以使用Image控件,需要使用绝对路径并加file://前缀。可能需要借助C++来取得QDir::currentPath路径:
// ApplicationUI.cpp
 
// Load the QML file
QmlDocument *qml = QmlDocument::create("asset:///main.qml");
 
// Retrieve the path to the app's working directory
QString workingDir = QDir::currentPath();
 
// Build the path, add it as a context property, and expose
// it to QML
QDeclarativePropertyMap* dirPaths = new QDeclarativePropertyMap;
dirPaths->insert("camera", QVariant(QString(
        "file://" + workingDir + "/shared/camera/")));
qml->setContextProperty("dirPaths", dirPaths);
// main.qml
 
// Load the image asynchronously
ImageView {
    imageSource: dirPaths.camera + "camera0001.jpg" 
}



从网络得图片是异步操作,需要在Image中包含ImageTracker,将它的imageSource属性设置为图片地址,并编写onStateChanged事件处理函数,赋值Image.imgae =
ImageTracker.image:
ImageView {
    id: myImageView
    attachedObjects: [
        ImageTracker {
            id: tracker
            imageSource: "images/image.png"
               
            onStateChanged: {                    
                if (state == ResourceState.Loaded)
                {
                    myImageView.image = tracker.image
                }
            }
        }
    ]
}

参考网页:http://developer.blackberry.com/cascades/documentation/ui/image_resources/index.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值