Getting max dimensions for an image - actionscript-3

I'm working with a maximum constraint on dimensions of bitmapdata in as3. I'm trying to find the maximum width and height that conform to the constraints below and also maintain my aspect ratio of my image as it currently stands. My image is 2980 x 3220 (width x height).
Bitmapdata constraints:
In AIR 1.5 and Flash Player 10, the maximum size for a BitmapData object is 8,191 pixels in width or height, and the total number of pixels cannot exceed 16,777,215 pixels. (So, if a BitmapData object is 8,191 pixels wide, it can only be 2,048 pixels high.)
If you could let me know how you arrived at your answer that would be awesome too
Edit:
find values for width and height where width / height = ratio = 0.9254658385
AND
width * height = some number as close to, but not exceeding max pixels (16,777,215)

2980*3220=9595600. Now, if we divide 16777216 by this number, we'll receive how much more pixels can your bitmap have while remaining in the constraints = 1.7484. To maintain aspect ratio, you have to increase both width and height by the same percentage, thus we need to take a square root of this = 1.3222 (this is rounded down at 4th digit). Multiply your dimension by this, receive 3940*4257, totaling 16772580 pixels, and both width and height are less than 8192.
So, your image can have at most 3940 width and 4257 height.

Related

In FasterRCNN, why is the short edge size 600 and the max size 1000?

I read the following code:
https://github.com/endernewton/tf-faster-rcnn/blob/a3279943cbe6b880be34b53329a4fe3f971c2c37/lib/model/config.py#L63
600 is the pixel size of an image's shortest side, and 1000 is the max pixel size of the longest side of a scaled input image.
Could anybody explain this? and how to determine these sizes? Shall we change these sizes?
These are used in prep_im_for_blob function in here. Where target_size is __C.TRAIN.SCALES = (600,), and max_size is __C.TRAIN.MAX_SIZE = 1000. What it does is scales the image so that the minimum size of the resized image is equal to __C.TRAIN.SCALES. However if the resulting image becomes bigger than __C.TRAIN.MAX_SIZE it scales so that maximum size of resized image is equal to __C.TRAIN.MAX_SIZE. If your input image typically falls within 600~1000 pixels in range, you don't need to change these values.

Why is the content

In AppDelegate.cpp , we have the following code in bool AppDelegate::applicationDidFinishLaunching():
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
auto frameSize = glview->getFrameSize();
// if the frame's height is larger than the height of medium size.
if (frameSize.height > mediumResolutionSize.height)
{
director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
//Add Code to use large assets
}
// if the frame's height is larger than the height of small size.
else if (frameSize.height > smallResolutionSize.height)
{
director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
//Add Code to use medium assets
}
// if the frame's height is smaller than the height of medium size.
else
{
director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
//Add Code to use small assets
}
director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
Why do we take the MIN of the ratios of the height or width ? Why don't we always take either the height or the width ? Won't this be inconsistent?
Since the assets we use are fixed in size (for example, in each block we either pick the large, medium or small assets), isn't the scaleing different for different aspect ratios, that may have the same height or width ? Wouldn't this lead to even worse problems like the physics and images on screen not matching ?
Because if you pick maximal scale it won't fit in height/width (depending of orientation).
for example designed resolution 960x640
resolution of background sprite 1024x768
1024/960 * 1024 ≈ 1092 - max
640/768 * 1024 ≈ 853 - min
so if you pick maximum your bg with will be wider then designed and stripe 80px wide will be out of screen.
otherwise, your bg will fit into designed width with some black stripes aside of it (960-853)/2 px wide.
Related information

Changing view-port max width

Is there a way to change the maximum width of the container(body or html or etc...) so that in a larger screen I can maintain the sizes of the elements as they are in a maximum width screen?
I've been using 'vw' for all the dimensions and want to know whether there is a way to set a maximum size for a 'vw' unit.

Decreasing image pixel size in actionscript?

I want to decrease an 480 X 480 bitmap image size to 30 X 30 pixel size but keeping the whole height and width intact. (I do not want to scale or use height/width property! )
So if i divide 480/16 = 30. So i need to take average pixel values of 30 pixel elements and put it into new image.
How to take the average in actionscript 3.0? I looked at getpixels() method, is their any simple way/methods to achieve this?
Let me put in more simple way - I am trying to reduce pixels in an bitmap image from 480 X 480 to 30 X 30, the height and width remain same and i expect some amount of distortion after converting image to 30 X 30.
I did scaling but it reduces width and height, if i again increase width and height it just regains normal pixels. Thanks!
Why don't you simply then make a copy of the whole image in code, but use the simple scaling to scale the copy, and only present that to the user. Also look at this from Stack Overflow
How to resize dynamically loaded image into flash (as3)

Fit a swf into a box keeping the same ratio

Here's one for the maths demons out there!
I have an as3 app that loads SWF's with various movie clips inside with a size of 1280 width and 720 height. I would like to fit these SWFs into a content box of height 885 width by 500 height. The SWF must keep a ratio of 1.77. This would be easy if as3 recognised the SWF being 1280 height by 720 width. It doesn't however, and takes the size of the movie clips inside the swf which varies (as long as it's within the original size boundaries).
Does anyone know how I can make the SWF's fit into the content box even if the movie clip sizes and therefore the original SWF sizes vary?
Thanks
If you know the original size and it will always be the same then you can just set the scale manually based on the ratio between the original size and the target size.
885 / 1280 = .69140625
500 / 720 = .694444444
so you can just do:
mySwf.scaleX = mySwf.scaleY = .69;
And it should be scaled properly.