Titanium ImageView无法通过设置高度和宽度属性来缩放大小?

时间:2013-06-05 06:02:19

标签: imageview titanium

我正在尝试将图片显示为我的应用程序的背景,我尝试使用ImageView,代码自爆:

            bg-img = TUI.create-image-view({
            image: ev.media
            left: 0
            top: 0
            border-width: 2
            border-color: "red"
            # width: img-width + "px"
            # height: img-height + "px"
            })
        bg-img.width =  2754 
        bg-img.height = 4896 
        # pic-img.add bg-img
        bg-img.add-event-listener \click, !(ev)->
            log \clicked-on-pic-img
            _this.trigger \click-edit-pic-view, ev
        # # inspect pic-img
        _this.Els.pic-container.add  bg-img

图像在屏幕上没有显示,但如果我减去bg-img的大小如下:

                bg-img = TUI.create-image-view({
            image: ev.media
            left: 0
            top: 0
            border-width: 2
            border-color: "red"
            # width: img-width + "px"
            # height: img-height + "px"
            })
        bg-img.width =  2754 / 3
        bg-img.height = 4896 / 3
        # pic-img.add bg-img
        bg-img.add-event-listener \click, !(ev)->
            log \clicked-on-pic-img
            _this.trigger \click-edit-pic-view, ev
        # # inspect pic-img
        _this.Els.pic-container.add  bg-img 

它无法正常运行,我不是为什么? O(╯□╰)○ 有人可以帮忙吗? THX!

1 个答案:

答案 0 :(得分:0)

我的原始代码很自然,我的目的是从photogallary动态获取图像,并将img设置为View的backgroundimage,其大小由图像决定: (我使用https://github.com/6174/TiDraggable模块)

create-pic-view.bind \photo-gallery, ->
_this = @
log \open-photo-gallery
Ti.Media.open-photo-gallery({
    success: !(ev)->
        log \success-get-image-event
        # inspect ev
        #image size in pixels
        img-width =  ev.width 
        img-height = ev.height  
        # convertPointToView( Point point, Titanium.UI.View destinationView ) : Point
        # Translates a point from this view's coordinate system to another view's coordinate system.
        pic-img = _this.Els.pic-img =  draggable.create-view({
            background-image: ev.media.native-path
            top: 0
            left:  0
            width: img-width  
            height: img-height  
            }) 
        pic-img.add-event-listener \click, !(ev)->
            log \clicked-on-pic-img
            _this.trigger \click-edit-pic-view, ev
        _this.Els.pic-container.add  pic-img    
    })