Scaling images fo tablet

31 views
Skip to first unread message

Gareth Murfin

unread,
Feb 7, 2020, 6:25:30 AM2/7/20
to CodenameOne Discussions
I just watched this https://m.youtube.com/watch?time_continue=654&v=sK-u1TBWFX8&feature=emb_logo

But it doesnt really explain what to do on a tablet. For example im testing now on galaxy Tab A, lots of my images are small and could take up much more of the screen. How do I deal with this without breaking all the sizes etc on the mobile where it already looks perfect? 
For now im doing if (isTablet()) and then calling scaledLargerRatio on the images (*2), this works but im wondering if it is bad practise? 

Dave Dyer

unread,
Feb 7, 2020, 3:55:02 PM2/7/20
to CodenameOne Discussions

I make sure the base image looks good on the largest screens and scale everything down to exact size at run time.
To accomplish this without a bunch of in-line code, I draw everything through a drawing proxy which maintains a cache
of scaled-to-size images.

Shai Almog

unread,
Feb 8, 2020, 12:25:52 AM2/8/20
to CodenameOne Discussions
Normally in an app you want to better use the tablet screen not to take up more room. I'm assuming this is for a game where the situation is a bit different sometimes.
See the cn1pocker demo. It includes this:

            UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
            cards = Resources.open("/gamedata.res", calculateDPI());

Notice we give the target DPI explicitly which lets you determine the DPI you want on the given device.

Gareth Murfin

unread,
Mar 18, 2020, 9:00:17 AM3/18/20
to CodenameOne Discussions
Thanks guys, thats nifty! Will give it a shot.

Gareth Murfin

unread,
Mar 23, 2020, 8:03:16 AM3/23/20
to CodenameOne Discussions
Actually I cant figure out what youre doing there.. I never call Resources.open, it seems to be done already when it comers into initVars? Do I need to do it again and pass the dpi? And why isnt there simply a version of getImage() that lets you get images from any DPI?

Also it doesnt seem to work for me, no matter what I call it always gives me back the same images:

example inside initVars I do

res= Resources.open("/theme.res", Display.DENSITY_LOW);

or 

res= Resources.open("/theme.res", Display.DENSITY_2HD);

but the images still look identical?

I expected them to be different sizes?


On Saturday, February 8, 2020 at 1:25:52 PM UTC+8, Shai Almog wrote:

Gareth Murfin

unread,
Mar 23, 2020, 8:11:53 AM3/23/20
to CodenameOne Discussions
oh it did work for some images, im just a little confused really, I know tablet should maximise screens better, but icons looking tiny is weird.. ill bring them in larger and reduce them via code for phone.

Shai Almog

unread,
Mar 23, 2020, 11:26:16 PM3/23/20
to CodenameOne Discussions
We don't load the image in all resolutions... We discard unnecessary data otherwise RAM would be packed with multi images.
Initializing the look and feel to create the theme implicitly loads the resources.
Reply all
Reply to author
Forward
0 new messages