2013-06-05 52 views
0

我想要显示的图像作为我的应用程序的背景下,我尝试使用的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 

的图像不会在屏幕apear,但如果我减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 有人可以帮忙吗?谢谢!

+0

你能显示你写的实际代码吗? –

回答

0

我出身代码更是一泻千里,而我的目的是要动态得到photogallary一个形象,并设置IMG为查看其大小由图象来决定的背景图片: (我用的是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  
    }) 
+0

当图像像480X640那样小时它可以正常运行,但是如果图像比1200X3600大。背景图像不会显示! – 6174

相关问题