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é

Tags: BlackBerry Developers

Similar Questions

  • 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!

  • 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-...

  • Minimum height and width does not work in the responsive project

    I'm working on a responsive project in Captivate 9, breakpoint Office, for one of the items minimum height 50px and Minimum width to 50px.

    In points out of office and Tablet, she gets no smaller than 50px. However, breaking Mobile, point it turns into 32px Min-Height and Min-Width 4.0px.

    The 32px Min-Height and Min-Width 4.0px take a coral color in the breakpoint Mobile.

    Why don't the 50px which was update to stop Office remain the same on all breakpoints?

    What is the purpose? A 50 x 50 pixel png? I just create a project that is sensitive with a png of 200 x 200, placed in the desktop view and then set the size of the object and the height to 50 pixels. When I pass between breakpoints, the size remains the same. The size and position properties are all a light purple color on each breakpoint, which I guess means that these attributes are inherited from the Office discovers.

    If the boxes under "Height" and "Width" have transformed a coral-colored, I guess that means that these attributes have been changed for this breakpoint.

    And you obviously already know. I guess that I'm just trying to say that he expected to run, as it does for me!

    You are able to adjust these modified figures go back to your desired size? The same thing happens if you create, say, a dynamic square object in the view of the Office? Have you tried right clicking on the object in the desktop view and selecting "Apply position properties from all points of view"?

  • Animate FancyBox iframe in Edge - do not show the correct height and width

    Hi all

    Can someone please provide advice or a solution to this problem.

    I tried to use the edge Fancybox.js animate to call an iframe (as a pop up album).

    However when I try this it does not show the correct height and width properties - even though I am their definition.

    When I test this on my hard drive it works fine in Chrome and Firefox. But when tried on line on a test server I get a slim pop up that has not properly set the height.

    Would be - because the iframe is pre-configured before composition/html page first affecting the size?

    Help, please

    CODE USED:

    $. fancybox.open)

    {

    type: "iframe"

    autoScale: 'false. '

    height: '600'.

    Width: '600',

    HREF: 'llink.htm site publication. "

    }, {

    padding: 0

    });

    Other references: http://businessanywhere.biz/blog/2013/03/adding-a-lightbox-to-edge-animate/

    See you soon,.

    Jason

    HI koyissa,

    Thank you for your response to this.

    I worked on what was the problem - my external publication that was created to animate dashboard was centered horizontally and vertically.

    He created the problem. When I took this out of the box of fancy worked well.

    See you soon,.

    Jason

  • How to set the size (height and width) 100% swf

    Hi all

    Here, I want to put my SWF height and width to 100%.

    If I want to increase my height by hanging out on my corner SWF then automatically the width should change.

    If the two should be 100% in all cases. How to get there.

    In the browser? Flash can not set the size of itself - its size is defined in the HTML code. You must use JavaScript to set the Flash object width and height on window resize event.

  • How to change the runtime of height and width of the front panel

    How to change the front height and width during execution. Basically, I want to decide height or width according to some parameters that I'm in the moment of execution.

    Ed johnsold was first

  • How can I control the monitor photo height and width with XP?

    Having 24 ' ASUS monitor.  There are no controls for the height and width of the image.  Operating system is Windows XP.  How can I change picture height and width?

    Hello

    You can try to change the resolution of the monitor screen and check if that helps.

    To change your screen resolution

    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/display_change_screen_resolution.mspx?mfr=true

    If you want to change the position and other options that are provided as an option on the screen of the monitor you can see the manual provided by the manufacturer or contact the manufacturer for more information about the options provided in the monitor to change the position of the screen.

  • Cut the bitmap given the height and width

    Hello guys '

    I need to cut bitmap with the given height and width settings.

    Are there examples of code?

    Please help me guys

    By 'cut' do you mean 'crop '?

    public Bitmap cropTo(Bitmap src, int newWidth, int newHeight) {
        Bitmap cropped = new Bitmap(newWidth, newHeight);
        Graphics croppedGraphics = new Graphics(cropped);
        croppedGraphics.drawBitmap(0, 0, newWidth, newHeight, src, 0, 0);
        return cropped;
    }
    
  • Request for information on the height and width of display devices

    I want to know the width of screen blackberry devices and the height from 4.5 os. I want the list of devices with their height and width of the screen. Where can I find them?

    Concerning

    Rakesh Shankar.P

    You can check this one also, more details

    http://docs.BlackBerry.com/en/developers/deliverables/11886/BP_controlling_resource_size_619260_11.j...

  • 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; »

  • 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

  • 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.

  • How keep the anchor in the Middle during the change of height and width for extendscript model?

    When I try to change my composition height and width using extendScript, it works but with anchor point at the upper left corner. How to maintain it in the Center?

    My code:

    COMP. Width = 4000;

    COMP. Height = 4000;

    result:

    result.jpg

    expected:

    expected.jpg

    Thank you

    OK, here is therefore the function for resizing of the model code. I tested several times with anchor points are offset on layers and centered, even with layers that are not yet within the limits of the Model Viewer. I'm sure there will be some users who eventually find something that will break it, but for now it seems to work perfectly.

    app.beginUndoGroup("CompResize");
      var myComp = app.project.activeItem;
      resizeComp(myComp, 500, 500);
    app.endUndoGroup();
    /* TESTING ABOVE */
    
    function resizeComp(compObj, newWidth, newHeight){
      if(typeof newWidth == "number" && typeof newHeight == "number"){
      if(compObj instanceof CompItem){
      var locData, allLayers, allLayersLen, curLayer, clAP, clPos, xShift, yShift, oldCW, oldCH, clH, clW, xOff, yOff;
      pData = new Array();
      cWidth = newWidth;
      cHeight = newHeight;
      allLayers = compObj.layers;
      allLayersLen = allLayers.length;
      oldCW = compObj.width;
      oldCH = compObj.height;
      compObj.width = cWidth;
      compObj.height = cHeight;
      for(var i=1; i<=allLayersLen; i++){
      curLayer = allLayers[i];
      clW = curLayer.width;
      clH = curLayer.height;
      clPos = curLayer.transform.position.value;
      clAP = curLayer.transform.anchorPoint.value;
      xShift = (oldCW - cWidth)/2;
      yShift = (oldCH - cHeight)/2;
      curLayer.transform.position.setValue([clPos[0] - xShift, clPos[1] - yShift]);
      }
      }else{
      alert("Invalid argument(1):\nComp Object required.");
      }
      }else{
      alert("Invalid argument(2/3):\nInteger required for Width and Height.");
      }
    }
    

Maybe you are looking for