flex - Resizing Image from a decoded ByteArray -


I am trying to display a biature as a resizing image. Image is displayed properly, but resizing is off. Let me explain.

First of all, the image data has been encoded, so I have to decode image data

  // Install the decoder work decoder: Base64Decoder = new Base64Decoder () ; // decoded image data decoded.decode (picture.data); // Export data as a byte array byte array: byte = decoder To Batere (); // display image var img: image = new image (); Img.load (bytearray);  

This works the image is displayed properly, however, if I hardcode the image (IMG) height then the resized image is displayed correctly, but the original image In the box with dimensions

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

The best way to clarify the problem is by placing the image inside VBox and showing the boundaries of VBox. From the above code block, if I change the image height and set the image to maintain the aspect ratio (which is set by default, but I add it to perfection). The problem is clear

  // im display image im: image = new image (); Img.height = 75; // hardcode image height (thumbnail) img.maintainAspectRatio = true; Img.load (bytearray); // VBox = Explain the VBox image inside VBox to clarify the problem; Vb.setStyle ('border style', 'concrete'); Vb.setStyle ('border color', 'red'); Vb.setStyle ('Straight Border', 2); Vb.addChild (img);  

I am working on this problem for days and can not come up with the solution. any idea? What am i doing

The procedure I used is as follows:

I img display object Become an event listener for After IMG loaded, I'm manually setting the height and width of the image. I know that I should be preHeight so that it is hard. I then calculate the width and set the image as width.

img.addEventListener (FlexEvent.CREATION_COMPLETE, I onCreationComplete); Private Function (Event: Flex Event) on Creative Compact: Zero {img.addEventListener (event.complete, on imageload complete); } IMAGE load on the private function (Event: Event): Zero {var image: image = Event as currentTarget image; Var preHeight: number = 0; Var h: uint = bitmap (image.content) .btmapData.height; Var w: uint = bitmap (image.content) .btmapData.width; // check height preHeight = h> 170? 170: H; // Set the width img.explicitWidth = (preHeight * w) / h; Img.explicitHeight = preHeight; }


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -