Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to rescale the images used in my livewallpaper, the problem I am having is how to rescale smaller animation that fit in a certain x and y position so it looks like its attached to a certain spot on the background image once that gets rescaled as well so it can fit in any screen resolution.

Any help would be appreciated
Posted

1 solution

One solution I came up width would be rescaling with this math.
get screen height divide it by background image height (since it will be maxed out and always bigger or at least the same size)
this will give a rescaling size percentage to rescale everything else.
example: screen resolution=800 background image=1000
screen height / background height = 0.8 or 800/1000=.8
then times rescale percentage by background height
rescale * background height = 800 or .8 * 1000 = 800 (the new height)
I know this isn't java or android coding here its just the math to do it with.
so the rescale number can work with all width and heights for everything else to rescale it perfectly.
Make sure its a float though.
Another example: I have a image 200px width by 400px height
the rescale number is .8
200 *.8= 160
400 *.8= 320

the new dimensions rescaled to fit the screen resolution would become 160px by 320px

This will work for positioning images in the perfect spot also

Lets say you got an image at 50x by 320y
use the rescale number to do this also.

.8 * 50 = 40 new x position will be 40x
.8 * 320 = 256 new y position will be 256y


Hope this helps someone.
I'm trying to think of the best way to create the bitmap so it doesn't become a resource hog and cause jittery images in the animations.
Maybe someone has an answer to this one.
Might make a nice tutorial once its all done :)

Hopefully since I got this far, I'll come up with a quick tutorial for this one since it was the bane of my resistance for about 4 hours and I searched a lot of places but I guess I wasn't asking the right question to get the right answer.
It's so simple to just get that one number and use it everywhere.

Oh ya to upscale (since this is actually a downscale or the same height) you would times instead of divide, since I am maxing out the backgrounds in the live wallpaper it should always be the way I stated, if your not sure if its bigger or smaller you can always use an if else statement to see if the background image is smaller or taller then the screen height then do your equation to get the rescale number.
 
Share this answer
 
v2
Comments
Sandeep Mewara 7-Mar-11 1:26am    
Good work.

Good thinking of posting it here for someone facing the same in future. :thumbsup: 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900