how to get scaled height and width? - actionscript-3

I have a s:Group with few fixed size components in it, these are lets suppose 200x300, 300x150 etc
Now if i resize s:Group with resizeMode=Scale, (scale down). and try to read the scaled down size of these child components but they still has the same old height and width.
how can i get width and height after scaling down the parent group?
Thanks

Try myComponent.transform.pixelBounds.width. That should give you an actual measured width wrt the visible X-Axis. If you are rotating, but you want the scale along X-Axis wrt the component, see this post on obtaining the scaling of an object.

Hey there :]
At first i thought it would be an easy task to get the width and height. But when i tried it, none of explicitWidth and measuredWidth worked, when resizeMode is set to "scale" of the s:Group.
So i found a way but i'm not sure if it's the best solution:
write this in your script tag:
import mx.core.mx_internal;
use namespace mx_internal;
then if you have
Group id="group" resizeMode="scale"
and a s:Button id="myButton" inside it
in order to get the myButton width for example, just compute group.$scaleX * myButton.width
Hope this will work.
all the best,
blz

Related

Scrolling (and eventually zooming) an SVG viewport

I have a graph rendered as SVG by Angular in a web page. The size of the SVG is dynamic, with its width being 100% of its container. I'd like to be able to scroll (and eventually zoom) the SVG's viewport. I'm not talking about the browser scrolling, but rather manually implemented scrolling by dragging on the background of the SVG.
I know I can use viewBox to do this, and changing the first two numbers works well, but the problem is that the second two numbers need to match the CSS width and height to be at 100% zoom. How do I work around this? Do I constantly need to update viewBox in response to the container size changing (e.g. when the browser window changes size) so it matches the CSS size?
There are many similar questions on here, but none that I can see are about this specific issue.
Update: I think I solved the first part of the problem using:
<svg #svg attr.viewBox="{{-scrollX}} {{-scrollY}} {{svg.clientWidth}} {{svg.clientHeight}}">
But I'm a little suspicious of its efficiency.
I still need to figure out how MouseEvent coordinates interact with this to be able to update my scrollX and scrollY, as well as how to make the SVG grow bigger as it needs to (but not bigger on the screen).

HTML Image Sizing and Variables

I'm using an application called iDashboards, and in it there is a feature I can add called a ViFrame that takes very limited HTML to create a custom frame.
My knowledge of HTML is already pretty limited and with no output feedback, it's hard to use trial and error as a tactic.
I'm trying to display an image. The image changes dependent on the person that's selected in the app. The selection is taken care of by itself, but the problem is that the size of the pictures vary. I'm trying to display the image so that it has a definite height and a scaled width.
Displays the full size image. The HEIGHT element doesn't seem to constrain anything. If I add a WIDTH tag it works but the scaling would be messed up. Is there any way to do what I want?
The way I see it, I have two options I can think of:
1. Make every image in the library a square and then specify square dimensions so no distortion
2. Somehow retrieve the original height and width into variables in HTML and specify both tags with height being constant and width being an expression of the ratio between height and width. None of which I know is even possible. Is it? I don't think it allows tags either to go into JavaScript.
Sorry about my very basic knowledge in HTML, be gentle.
Are you using one object and changing the image or using many images and changing which one is displayed? Any way you could try to use width:YOUR_VALUE_HERE; height:auto in your css document, which should keep them all in the same ratio.
Set a particular class on the IMG tag:
<img class='constrained_img' src='/path/to/img.png'>
In your CSS/Stylesheet:
.constrained_img {
max-width:100px;
max-height:100px;
}
That should keep your height and width to no larger than 100px in this case. Any further work you'd need to do server-side processing (a la PHP's getimagesize()), or use a 3rd-party library (I've used Joseph Lencioni's SLIR to good effect), or muck around with JavaScript (which isn't impossible, but off the top of my head I'm not sure how I'd go about it).

How to display image larger than 10000 px width or height?

I have found some problems in displaying images larger than 10000px width or height in spark Image component. Despite of setting maximum width/height or explicit width/height to larger sizes the image is being scaled down to 10000px.
<s:Image id="image" source="big.jpg" maxWidth="20000" maxHeight="20000" width="14400" height="10800" x="-9200" y="-8200" />
<s:Label id="debug" />
I set these coordinates to be sure I see the bottom right corner of image (it's scaled down proportionally). In debug I'm displaying the mouseX and mouseY of image.
protected function application1_mouseMoveHandler(event:MouseEvent):void
{
debug.text = image.mouseX + ", " + image.mouseY;
}
Image component uses BitmapImage internally: Image.imageDisplay.
If BitmapImage works fine, manually setting maxWidth and maxHeight of Image.imageDisplay might fix the bug.
Added:
When you manually setting the maxWidth and maxHeight of imageDisplay, I recommend using a custom Skin to set them. Or they could be set after the image is loaded and scaled already.
Additional Information:
The default value of BitmapImage.scaleMode is stretch, but the default value of Image.scaleMode is letterbox. So, if you see BitmapImage works fine but Image scales differently, check this property.
The answer is simple - check out the documentation: http://flex.apache.org/asdoc/spark/components/Image.html
Maybe I should write it here, as nobody actually reads that docs - 10k is the limit of both width and height for that component.
edit: Are you serious you need image larger than 10k?! Can you imagine how much memory this is? :)

Defining the width of a div as a percentage of the height

I need to preserve the aspect ratio of a div when the browser window is resized.
I have done a good bit of searching on this, and it is possible to use padding to preserve the aspect ratio of a div by making its height relative to its width, whenever the width of the screen is altered.
The technique is shown here on Stack Overflow, and in particular, this linked to example shows the technique in action.
But I need to do the opposite. Rather than making the height relative to the width of the div, I need the width of the div to change whenever the height of the browser window is altered. I need to do this because I have a background image that I want the content to flow relative to, and that background image has a 100% height, and its aspect ratio is preserved.
I have tried using linked method, but swapping horizontal for vertical attributes. It isn't working. I have no idea why. Perhaps someone can show how to do this.
I need the width of the div to change whenever the height of the browser window is altered.
For a pure CSS solution to that, you will have to wait for a broader implementation of either calc() or the vh unit.
I don't know if this is possible in pure CSS, but there is a possible way with jQuery, see this discussion
Maybe something like mmoustafa suggested:
$(window).resize(function() {
$('#my-div').css('width', window.innerHeight*0.4+'px');
$('#my-div').css('height', window.innerHeight*0.2+'px');
});

making huge pixel images fit to the given width and height

I got a problem with images and its pixels probem.well let me tell you this.I got a picture of 2448 x 3264 pixels. So its a big image I just decided to reduce its size using this way
<img src="1.jpg" style="width:600px;height:500px"/>
But there is a problem I see, the picture looses its clarity and its visibility, it looks like pulled it close and the person in the images looks so ugly.but using the original size makes look so big . I am sure there is a way to do because I see google images result and also on some websites I tried to see thier code but Could not figure it out.
Could anyone please tell me how do i make the images look good even when they got too long resolution and make them fit in the given width?
Update
Okay now i understand we need some server side image processing and could anyone tell me what would be the way to do it Thanks
The most wide-used practice is to resize the image server-side. When the image is uploaded to the server (e.g. by the user) the server takes it and creates and creates needed thumbnails.
Unfortunately this cannot be done with HTML, CSS nor JavaScript. And there are a lot of cons of forcing the size of the image with CSS. For example the user have to download the whole image ( I guess yous is about 6MB ) and it could take a lot of time .
Withour any language you cant do it, or you have to edit the image and need to upload to your host.
Try using the plain html. It will also help if you have the right width:height ratio (in this case, 3:4)
so:
<img src="1.jpg" width="375" height="500"/>
To gain better quality you need something more, then only HTML. You have to resize images manually, either use some server-side scripting to prepare images before rendering (better even do it on uploading if you sure about specific dimensions).
What you need is server side image processing. For exaple phpThumb or another implementation depending on your serwer platform.
Example:
<img src="../phpThumb.php?src=1.jpg&w=600" />
the phpThumb will open image passed in src, and resize it to width passed in w -> the process image on the fly and outputs to the browser.
For pictures to maintain their clarity, you need to ensure that you maintain aspect ratio. Aspect ratio is the width/height ratio of images and if you resize images maintaining the ratio, then their clarity is maintained. You are getting the resized image to be messed up because 2448/3264 != 600/500.
Now tag resizes by aspect ratio, if you give only one of the attributes of width or height. eg:
<img src="your_src" width=600>
This will render maintaining aspect ratio(it calculates the height needed). However, this could lead to problem sometimes if you have a max-height constraint, because the recalculated height could exceed the div height, if your div has a max-height.
If you have a max-height and max-width constraint, you can use the following code to resize the image using JS. I am assuming that max-width and max-height values as 600px and 500px respectively and you can change as per your needs:
height = this.clientHeight;
width = this.clientWidth;
aspectRatio = width / height;
if (height > width)
{
height = 500;
width = height * aspectRatio;
}
else if (width > height)
{
width = 600;
height = width / aspectRatio;
}
this.setAttribute("height", height+"px");
this.setAttribute("width", width+"px");