Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 421661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:00:18+00:00 2026-05-12T19:00:18+00:00

I am trying to display a bytearray as a resized image. The Image is

  • 0

I am trying to display a bytearray as a resized image. The Image is displaying correctly, but the sizing is off. Let me explain.

First I have the image data encoded so I need to decode the image data

// Instantiate decoder
var decoder:Base64Decoder = new Base64Decoder();
// Decode image data
decoded.decode(picture.data);
// Export data as a byteArray
var byteArray:ByteArray = decoder.toByteArray();
// Display image
var img:Image = new Image();
img.load(byteArray);

This works. The image is displayed correctly. However, if I hardcode the image (img) height the resized image is shown correctly, but within a box with the original image’s dimensions.

For example, if the original image has a height of 300px and a width of 200px and the img.height property is set to 75; the resized image with height of 75 is shown correctly. But the resized image is shown in the upper left corner of the img container that is still set to a height of 300px and a width of 200px. Why does it do that? And what is the fix?

The best way to illustrate the problem is by placing the image inside a VBox and show the borders of the VBox. From the code block above, if I change the image height and set the image to maintain aspect ratio (which by default is set to true but I add it here for completeness). the problem becomes clear.

// Display image
var img:Image = new Image();
img.height = 75; // Hardcode image height (thumbnail)
img.maintainAspectRatio = true;
img.load(byteArray);
// Encapsulate the image inside a VBox to illustrate the problem
var vb:VBox = new VBox();
vb.setStyle('borderStyle', 'solid');
vb.setStyle('borderColor', 'red');
vb.setStyle('borderThickness', 2);
vb.addChild(img);

I have been working on this problem for days and cannot come up with a solution. Any ideas? What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:00:19+00:00Added an answer on May 12, 2026 at 7:00 pm

    The workaround I used is as follows:

    I created an event listener for the img display object. Then after the img has loaded, I manually set the height and width of the image. I know what I want the height (preHeight) to be so that is hardcoded. I then calculate the width and set that as the image width. For some reason I had to use the explicitHeight and explicitWidth properties to finally get the sizing right.

    I hope this helps someone.

    img.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
    
    private function onCreationComplete(event:FlexEvent) : void
    {
      img.addEventListener(Event.COMPLETE, onImageLoadComplete);
    }
    
    private function onImageLoadComplete(event:Event) : void
    {
        var image:Image = event.currentTarget as Image;
        var preHeight:Number = 0;
        var h:uint = Bitmap(image.content).bitmapData.height;
        var w:uint = Bitmap(image.content).bitmapData.width;
    
        // Check height
        preHeight = h > 170 ? 170 : h;
        // Set the width
        img.explicitWidth = (preHeight * w)/h;
        img.explicitHeight = preHeight; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to display the image i have coming from an intent.putExtra on a
im trying to display data on the footer in jqgrid, but it only displays
Trying to display an image only for Android users, but I don't want to
Im trying do display my body onload in a div tag, but cant solve
Im trying to display in my website photos froma photoset I have in Flickr.
I have an array of Person pocos, populated below. I'm trying display them alphabetically
I am trying to display an image (byte array) using purely JavaScript. How can
Trying to display related data from a hasMany through table. It's finding the joinModel
I am trying display values in a datagrid in my application. I have all
I'm trying to display Tiff Images that I have a byte array for. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.