Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Image not scaling

I am placing an image for a button.
But the image is not scaling to the width of the button.
Is there anything I have to do to scale.
My code is

var register = Titanium.UI.createButton({
title:'Register',
image:'images/buttons/BlueButton.png',
height:50,
width:300,
top:340
});

— asked October 15th 2010 by Jacob John
  • iphone
0 Comments

2 Answers

  • Accepted Answer

    I posted this in the bug tracker because the documentation needs clarification or the functionality of "scaling" needs to change. (I would prefer the later)

    From the docs:

    Basic Image View
    In this example, we create a simple image view:
    var image = Titanium.UI.createImageView({url:'myimage.png'}); view.add(image);
    Notes
    If you specify a width and/or height property on the image, the image will be scaled to fit into this space if the image is larger.
    

    The Issue:

    The notes are not accurate. (with respect to iPhone and Android devices) You cannot specify [height and width] and get the image to scale on both axis. The ImageView will look at only one of those parameters and which parameter [height or width] Titanium uses is not clearly defined in the notes.

    Example1:

    var imgBackground = Titanium.UI.createImageView({
      image:'images/image_768x1024.png',
      width:300,
      height:50,
      canScale:true}); 
    
    Titanium.API.debug("Image Width: " + imgBackground.width);
    Titanium.API.debug("Image Height: " + imgBackground.height);
    

    Example2: (switched width & height values)

    var imgBackground = Titanium.UI.createImageView({
      image:'images/image_768x1024.png',
      width:50,
      height:300,
      canScale:true}); 
    
    Titanium.API.debug("Image Width: " + imgBackground.width);
    Titanium.API.debug("Image Height: " + imgBackground.height);
    

    The imgBackground.width & height report correctly as specified, but the image does not scale on both axis. In both examples the image displayed is of height 50.

    Example 1: Titanium decided to scale on height, but maintained perspective so image reports a width of 300, but actually displays a width proportional to the height of 50.

    Example 2: Titanium decided to scale on width, but maintained perspective again.

    So for the documentation to read correctly it should include the note:

    The image will be proportionally scaled, and will maintain the original aspect ratio displaying the image based on the height or width parameter which will produce the smallest image.

    — answered October 26th 2010 by Steven Day
    permalink
    0 Comments
  • I am working on my document image reading and processing SDK, including document page and image scaling using visual basic language:

    Public Shared Function ApplyResize(img As REImage, ratio As Single) As Integer

    — answered March 12th 2014 by HILLARY HALL
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.