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
Related
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.
I am using imgAreaSelect.js for image cropping.
Suppose there is an image of a 'rectangle' shape in the middle of the picture. On larger screen (desktop) when I select the rectangle shape, imgAreaSelect gives me its width & height (say 250 x 150 ). While on a smaller screen (mobile phone) it gives me width & height (say 100 x 50).
I use canvas to draw the cropped image on. So far I have been using the width & height obtained during selection as the width & height of the canvas. This produces images whose dimensions are bigger for the bigger screen while smaller for the smaller screens.
Is it possible in any way to get an image of a standard dimension whether it's cropped from a larger or smaller screen? If yes then do explain with some codes if possible. Thanks
I have set the height and width of my parent div to:
width:1060px;
height:650px;
Which gives me an appearance as far as its size in Chrome on my 720 laptop but when I plug the 1080 TV through the HDMI it's too little on the screen.
I wonder if there is a way to resize the parent div to keep the same distance I get from top/bottom/right/left for 16:9 ratio.
Yes, you need to trigger a resize on the container each time on orientation change with js, then calculate your designed width height aspect ratio, then resize your container to screen.height, then multiply your screen height * your desired aspect, then that result is your width, then check if your width is not minor than screen width, if not is good, if true make the same but in backwards, dividing screen width / desired aspect ratio. lastly center your container in the screen with js or css.
that is the idea, i know works because i ve done it, probably there will be an easy way to accomplish the same.
In this way you can build percentually inside the container and will allways look the same in any kind of stuff, the only change will be a strip on the width or height depending your aspect ratio and your device specs, but it will be allways at biggest possible way.
EDIT,
Is something like;
var ratio = 1060/650;
$(window).on('resize', function() {
$('#container')
.css({width: screen.width + 'px', height: screen.width*ratio + 'px'});
if ($('#container').height() > screen.height) {
$('#container')
.css({width: screen.height/ratio + 'px',height: screen.height+'px'});
}
$('#container').css({left: (screen.width - $('#container').width()) / 2+'px',
top: (screen.height - $('#container').height()) / 2+'px'});
});
In jsfiddle wont be nice as this is using screenwidth (you could also use innerHeight, depends if you are going full screen).
Didnt test it but thats the general idea
What you want is a responsive design. In order for your page to resize, you have to start using percentages instead of fixed widths.
For example, change your width:1060px; to width:90%;. The height can stay the same, but if you wanted it to get taller, you can set height:100% and that adjusts according to the content on the page.
Also, instead of using px for text-size, use em. em is like percentages for text.
Here is a great tutorial that helped me a lot with responsive design.
Use CSS media Queries to specify styles for different screen resolutions & sizes. Your browser will choose the respective style depending on the size of the view port.
Read more about that here -> https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
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.
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)