0

我正在尝试将图像显示为我的应用程序的背景,并且我尝试使用 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(╯□╰)o 有人可以帮忙吗?谢谢!

4

1 回答 1

0

我的原始代码被炸毁了,我的目的是从照片中动态获取图像,并将 img 设置为大小由图像决定的 View 的背景图像:(我使用 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    
    })
于 2013-06-05T23:55:57.127 回答