Get the height and width of an image

I have therefore some images in my program that I'm loading. These images are much longer than the size of the screen. So I put in a ScrollView. My question is how can I get the height and width of an image. The image.width and image.height doesn't return the correct values.

//add the image
private function addImage():Container {
    var sp1:Container = new Container();
    sp1.sizeUnit = SizeUnit.PIXELS;
    sp1.debugColor = 0xFFFFFF;
    sp1.margins = Vector.([1,0,0,0]);
    sp1.align =ContainerAlign.NEAR;
    //sp1.setSize(650, 800);

    var myPattern:RegExp = / /g;
    var fileName:String = "./com/swiz/img1.png";
    var icon:Image = new Image();
    icon.setImage(File.applicationDirectory.resolvePath(fileName).url);
    //icon.setPosition(0,0);
    //icon.setSize(320,800);
    sp1.addChild(icon);
    sp1.setSize(650, icon.height);

    return sp1;
}

and my code scrollview is

//add to the scrollView
var scroller:ScrollPane = new ScrollPane();
scroller.width = 650;
scroller.height = 505;
scroller.y = 0;
scroller.addScrollContent(addImage());
addChild(scroller);

Thanks in advance!

Hey shethab,

in order to retrieve the height and width of your image, you must use use the an event listener on your image and check for the Event.COMPLETE event. What is happening because the image you upload is not built, it takes time to load into your application using the setImage() method. and when you check the width height after the setImage method, the image was not loaded and has no height and width to this second. If you use the event listener, you can retrieve the height and width as it was finally loaded.

Try the following code:

import flash.events.Event;

//add the image
private function addImage():Container {
    var sp1:Container = new Container();
    sp1.sizeUnit = SizeUnit.PIXELS;
    sp1.debugColor = 0xFFFFFF;
    sp1.margins = Vector.([1,0,0,0]);
    sp1.align =ContainerAlign.NEAR;
    //sp1.setSize(650, 800);

    var myPattern:RegExp = / /g;
    var fileName:String = "./com/swiz/img1.png";
    var icon:Image = new Image();
    icon.setImage(File.applicationDirectory.resolvePath(fileName).url);
    icon.addEventListener(Event.COMPLETE, onImageLoaded);
    //icon.setPosition(0,0);
    //icon.setSize(320,800);
    sp1.addChild(icon);
    sp1.setSize(650, icon.height);

    return sp1;
}

private function onImageLoaded(e:Event):void
{
    trace("image height: " + e.target.height + " image width: " + e.target.width);
}

hope that somethings brightened. Good luck!

Tags: BlackBerry Developers

Similar Questions

  • Get the height and width of the jpg or png of bitmap without loading the file

    Is there a way to get the height and width of a bitmap, such as jpg or png file, without loading the complete file of the image first.

    Thank you!

    Hi JamesColeman,

    While you can't get the width and height of the jpg or png without access to the file, you can get this information without access to the entire file. A PNG for example (in raw hex) indicates the width and height of the image it contains. The first 21 bytes contain the file-specific information such as name, etc, but just after the IHDR header 4 bytes indicate the width and the other 4 bytes indicate height. If enough for you to read the first 29 bytes of the PNG to be able to get its dimensions, which, while it still requires access to the file is much easier.

    I have the code to read this information here and if you want to learn more about the specifications you can find information on this site.

    Best wishes

    André

  • get the height and width of the screen in QML?

    How to get the height and width of the screen in QML?

    Please search the forums before you make a new post. This post is still on the first page... http://supportforums.BlackBerry.com/T5/Cascades-development/correct-way-to-get-display-width-height-...

  • How to display the height and width of an image that I adjust them

    How display the height and width in pixels of an image that I adjust them until I actually have to crop the image?

    You can make the Panel visible Info and see dimensions in various operations.

    It is often useful to define the rules to read in Pixels (in the section units and rules of preferences).

    -Christmas

  • Get the height and width of the object of a threshold

    Hey guys,.

    I am currently working on the extraction of the human sillouhette. Currently, I am trying to retrieve the height and the width of a human sillhouhette for further analysis. Are there any screws for this? Or if any of you can recommend a method? I really need help. The 2 images below should illustrate what I'm talking about. Note that I have several images (various) to analyze a video.... Help is really appreciated. Thank you.

    Concerning

    This task could be run with IMAQ particle analysis Report.vi.

    Please note that this VI is installed with the Vision Development Module.

  • How to get the height and width of the exact text in TextLayout framework

    Hello fellow developers,.

    I'm starting to work with TLF when there are three different CFC now, I work with unique CFCS with flex 4 and a lot of things are changed as

    I use calculateHeight (), calculateWidth () now these methods are not available.

    If someone knows the replacement of these methods then do let me know.

    Thank you

    If the text exceeds the container, what can happen in a container to scroll where you have to scroll to see some of the text, then returns getContentBounds values are estimated values. It is because we do not want to force the text to recompose all the way at the end of a very long TextFlow in order to return a value. However, if you want to get the exact amount and is not afraid to take the time to redial, call textFlow.flowComposer.composeToPosition (), before calling getContentBounds. This forces all text redial at the end, and then getContentBounds displays the calculated value entirely instead of her estimate.

  • How to get the height and width of the screen of the blackberry device?

    Can someone tellme how to get details of the screen of the blackberry device?

    Display.getWidth () and Display.getHeight ().  If this isn't what you want, let us know.

  • What is the best way to resize an image, but keep the height and width of the same original size or format?

    What is the best way to resize an image, but keep the height and width of the same original size or format?

    I tried to use the function of the size of the Image, but when I changed the size of the image, the width has not changed with it.

    Thanks for the tips!

    Hi Landon.Luu,

    You want to keep the relationship between the width and height to be the same?

    Click the constraint between width and height to keep the ratio intact.

    Kind regards

    Claes

  • The height and width settings no longer work.

    Adobe Photoshop CS5 settings went crazy in the canvas size box.  Everything appears as 0, whether inches, pixels, etc.  I tried to enter numbers instead of the zeros in the height and Width boxes, and then it creates huge margins around the image.  If I cut the number in half to try to mislead the it, it still gives big margins instead of cropping the image.  Help!

    Looks like you have Relative checked in the canvas size dialog box.

  • show the height and width of the screen

    Is it possible to display the height and width of the screen in a labelfield?

    Yes. To do this, ask yourself two questions:

    (1) is it possible to display a string that I want in a LabelField? (The answer is Yes)

    (2) is it possible to set the height and width of the screen in a string? (The answer is Yes)

    (3) is it possible to find the height and width of the screen? (The answer is Yes)

    Now, just try to find how to do it ask these three questions. #1 is right there in the documentation for class, LabelField . #2 is trivial if all goes well. # 3, take a look in the view class.

  • How to set the height and width of dvt:piechart?

    Hello

    After upgrading to 10.1.3 jdev the new PIE is < dvt:pieChart >.

    I need to set the width and height or if not possible set the height and width of the container and let the repeating table using the container.

    Thanks in advance

    Emile BITAR

    Change this by using the attribute "inlineStyle". Set inlineStyle = "width: 200px;" height: 300px; »

  • Does anyone know the height and width that a dreamweaver layout grid can go?

    Does anyone know the height and width that a dreamweaver layout grid can go? (in pixels)

    To try:

    {body

    height: 36000px;

    Width: 40000px;

    }

    Nancy O.

  • Get the length and width of a rectangle

    I use sdo_sam.tiiled_bins in rectangles of bursting into different sections. I need to divide the rectangle along the x axis depending on if there is longer or wider. I checked the documentation and I couldn't find a way to get the length and width of a rectangle encompassing minimum. Is there any built-in feature to get the length and width of a rectangle or do I have to create my own? Database is 11 GR 2.

    Thank you
    Rob

    Rob,

    You can use SDO_GEOM. SDO_MIN_MBR_ORDINATE and SDO_GEOM. SDO_MAX_MBR_ORDINATE to calculate the length and width of a mbr.

    References:

    [SDO_GEOM. SDO_MIN_MBR_ORDINATE | http://docs.Oracle.com/CD/E11882_01/AppDev.112/e11830/sdo_objgeom.htm#i866250]

    [SDO_GEOM. SDO_MAX_MBR_ORDINATE | http://docs.Oracle.com/CD/E11882_01/AppDev.112/e11830/sdo_objgeom.htm#i866249]

    Kind regards
    Noel

  • Set the height and width of pop-up window.

    Hi friends,

    I have a button Add a new element on the page no 1.i have 3 not on page no 2 as ITEM_CODE, nom_element AND STATUS.
    I want when I click on add new item on the page no 1, and then open the page not 2 like a window popup with the height and width 500 700 and after press submit value insert into the table and pop-up window must be close.
    I take model Popup

    How can I adjust height n weidth of page 2 of the popup.


    Thank you

    Hello

    You must be a mistake. Process of Close popup works very well in Apex 3.2.

    Remove all branches of page 20 and check that you have not any condition the process Close popup

    Kind regards
    Jari

  • Discover the height and width of the selected content... ?

    Hello world. !

    I'm a new baby to the indesign script. In fact I link an Eps image to the picture box.

    now I want the height and the width of the image in eps, angle and also need to coordinates X and Y...

    someone help me... ?

    Thanks in advance.

    -yajiv

    Substances, which gives the width and height.

    The central point is at (geometricBounds [3] + geometricBounds [1]) / 2, geometricBounds [2] + geometricBounds [0]) / 2 (Alternatively, geometricBounds [1], geometricBounds [0] + width/2, height/2 - which is the same).

    With regard to the angle, rotationAngle sounds all right, but compare to absoluteRotationAngle - which seems to be a total value of several nested objects and rotation.

    Oh, and you want to shear as well?  Each widget also has a shearAngle and, to top it off, an absoluteShearAngle as well.

Maybe you are looking for

  • Audio embeddee Mail &amp; Safari is incomplete

    I'm using OS 10.11.4, Mail Version 9.3 (3124), Safari Version 9.1 (11601.5.17.1) and I have problems with audio integrated how appears. I've noticed this primarily by mail, so I'll focus on that. When I drag an audio file in an email I have to compos

  • Satellite M70-147 - the battery does not recharge

    Hello I have a problem with my battery, it seems that it does not re - pay.First of all, please read the following: -When I start the laptop with AC power plugged the battery seems to be charged to 100% according to the Toshiba Power Saver.-When I re

  • Satellite A300 - how to install Windows XP

    Hello In order to use certain virtual machines of Windows, I need to change my OS from Vista to Windows XP... My laptop is a Toshiba Satellite A300, equipped with Centrino 2 (2.26 Ghz), 4 GB of RAM I would like to know if it is easy to install Window

  • No message, no beep on Satellite P100-113?

    I changed the machine he went to the post OFFICE but has frozen on.I waited 3 minutes or so and that it restarted. No result no POST no beep without backlight of the screen but the amusements work he checks also the dvd player but that's all.tried up

  • I want to deleate recent research history of this computer

    Original title: I want to deleate recent research history for this computer in all programs on it. How can I do it without wiping the hard drive? Thank you