Image Sizes for Themes - java

I'm looking at making my own theme in CodenameOne but I cant find out quite what I need to do (I should point out I'm new to codename one)
From what I can see the key to what I need to do revolves around Multi-Images. I place an image there and the designer scales it multiple times so that I have all the images needed for the multitude of devices. Clearly, if it's scaling, the exact size of the image I put in Multi Image is a little irrelevant but what is the optimum size (presumably the close to the largest dimensions that will be used?). Can anyone give me an idea about the resolution of, say, a background image that I'm going to put into Multi Image and the correct (or best) aspect ratio?

Historically we recommended making retina iPhone sized images then importing them using the "Quick Add Multi Image" menu option and picking "Very High" as the target DPI.
This still works rather well but recently there has been an influx of higher DPI devices (iPhone 6+ and newer Android flagships) so we might update that guideline in the near future.

Related

Can we bypass HiDPI UI scaling when rendering high-res RenderedImages in Java 9+

I am working on a medical image viewer, and would like to take advantage of the HiDPI scaling options offered by Java since Java 9. I like that Java/Swing is not able to properly scale up fonts, layouts, and various UI elements, but as has been lamented in multiple posts in here, doesn't automatically do a good job with bitmaps, displaying icons and images in a very pixelated way.
I have seen several questions and answers in here about how to deal with badly scaled up icons. This is not what this is about.
My question is about displaying and interacting with high-resolution images without having them scaled up while rendering, when everything else in the UI is being scaled up. I don't want to turn off HiDPI scaling altogether, I want to use it for the UI.
Is there a way to selectively display RenderedImages in screen resolution, bypassing the scaling?
I took me a while digging through a lot of unrelated or tangentially related topics, but I did eventually find an answer to my own question here:
jdk 9 high dpi disable for specific panel

Java Swing app looks tiny on high-DPI screen when it should be scaled to normal size

How can I make my Java Swing app GUI scale properly to users on high-DPI screens?
See the screenshot below. At the top you can see how tiny the app looks compared to Ubuntu's file explorer icons and gedit. In the bottom left you can see roughly what size the app should look like (and does look on regular DPI monitors). So I'm looking for a way to scale the GUI of the app properly when a high DPI monitor is in use. For example, gedit looks the same on both regular DPI and high DPI monitors. I want my app to behave like this.
Here is source code for the app: https://github.com/baobabKoodaa/baopass
This is an extremely common problem affecting many apps. Roughly half of the apps I run on Ubuntu are scaled properly without any actions from the user, the other half are not scaled and look really tiny. Note that I'm mainly looking for a solution that doesn't require actions from the user (although any help is appreciated at this point - I haven't found any ways to scale it at all).
According to this scaling should already work out of the box. It doesn't. I'm not sure if this is a bug or if there is some additional step I'm supposed to do besides running the app on Java 9?
You have to tell the drawing libraries to scale the app up.
GDK_SCALE=2 ./application
Will have the appropriate information set in the environment and the widgets will render scaled up such that each pixel effectively takes four pixels of footprint.
Note that the splash screen (if you use Java's splash screen support) isn't presented after the entire Swing libraries are loaded, so it won't scale regardless of the settings you attempt.
In some platforms, like the Linux distribution of Fedora, partial scaling is also possible, such that you can set GDK_SCALE=1.5. Just keep in mind that it's not universally available, and it is not settable to any scaling ratio you might want.
Finally, the older JVMs ignore this setting completely, so if you aren't launching with Java 9 or higher, odds are it won't work. And, of course, the way that things are tweaked for older JVMs and different operating systems tend to vary (if they work at all).
It looks like you're using Linux. You can use a command line switch
java -Dsun.java2d.uiScale=2 -jar some_application.jar
From https://wiki.archlinux.org/index.php/HiDPI#Java_applications

Assets behaviour in multiplatform libGDX application

What is the best practice to store resources in libGDX library. I'm know that I can use AssetManager and also e.g. I can link the resources from android folder into iOS, but I dont know how it will behaviour on multiplatform devices. The resources are scale according to screen size/operating system, or I need to manually set diffrent size or resulution in each platform resource folder.I want to avoid any ovelaying or stretch behaviour.
There are many ways to go about this and there is no "best" solution. However if you do already build for android just use the android assets folder. This is the default and will be used for other builds (due to the default libgdx project configurations).
The resources only scale if you tell them too. You can choose to use a viewport (a fit/fill viewport will not stretch but can add black/background bars that do not have the default aspect ratio). But you can also choose to implement screen dependency yourself by using the aspect ratio and the scale.
For instance:
A 1080x1920 mobile phone vs a 1440x1920 tablet
If you use a fit viewport you will have unused space on the tablet. if you use a fillviewport you might lose stuff on the phone. But if you take the phone as a default aspect ratio and calculate the width offset for the tablet (1440-1080/2) you can use this value to choose to put actors/sprites on the same location as on the prone (by using this offset) or relative to the screen edge (by using the screen size). I personally use this to place the UI relative to the screen and the game itself the same as on the phone. You can even choose to use a different layout depending on the aspect ratio.
Do note that in this way you will also have to calculate a global scale and use this everywhere in your application. This can be tedious to implement but gives you much more control!
So if you have a simple game and you don't care about tablets or different screen sizes I suggest you start with a fit viewport.
p.s. Not sure what you mean by "multiplatform devices", but as I said, the default libGDX setup does the heavy lifting here, so I suggest you use it!

Is There A Way To Disable Mac OS Retina Scaling For A Swing App?

We have a rather complex application that needs as much screen real-estate as it can get, naturally the retina display Mac Books are excellent for this purpose.
However, it seems that in Swing those devices use points rather than pixels. They allow me to change the icons to higher resolution versions as discussed here. But since we do a lot of complex graphics and components overlays I want to just use "real pixels". To be clear I am not interested in fixing blurry images or icons (not practical in my case) just to disable the pixel doubling.
There is this interesting (albeit hacky) option I found thru this question.
To my knowledge this is not possible as of JDK 1.8. The only workaround is to detect retina and use the scale affine transform when drawing.
However, detecting retina seems to be a problem since the only option that seems to be available isn't on a per monitor case which is probably not a good solution:
How can I detect whether a Mac has a Retina display from Java?

Android drawable paradigm!

I have been developing Android application since 3 to 4 months. I am naive, But pretty much exposed to all of the fundamentals regarding application development on android. However I found really painful while developing application with lots of images, By saying images I mean one of my application has around 10 to 13 images(Small enough to accommodate screen size). The problem is I have to make different copies of it by making,
HDPI - High resolution support
MDPI - Medium resolution support
LDPI - Low resolution support
I have come up with an idea,
IDEA : My idea is to actually have only MDPI images in drawable folder, When my
application will installed first time, I want my application to detect what type of
resolution is supported by device? After knowing which resolution is supported one of my
built in method will either use a MDPI version(images), if handset supports it or else
it will scale up or scale down my images and stores into internal storage for future
reference. When user uninstall my application I will remove these images from internal
storage.
Now this idea has raised a question,
Question :
Whether this idea is feasible? and Programatically possible?
If it is, Should I be really concerned about one time computational overhead?
Is there any mechanism(third party) which can ease my problem? (I hate photoshop and scaling up and down all those images)
Any expert help or guidance will be a big favour!
Thanks in advance!
Krio
I dont really understand why you would do this. The system already basically does this for you. You dont have to specify different images for different display densities, the system just gives you the opportunity to so you can make your app look its best. If you only supply a single image the system will scale it appropriately for you based on the density of the handset.
As for help with scaling the images yourself for packaging, you could look at image magick. This is a powerful scriptable image manipulation tool. You might need to spend a bit of time getting up to speed with it, but I am sure you could write a script that you could reuse for all of your images after that to convert high dpi images to lower dpi ones by scaling down.
Take a look to this article. It describes how android handle directory names for resources. Also take a look a look to this - how android choose the best match for directory name. If you want to use the same resource for all dpis just place it in the default drawable folder.

Categories