简体   繁体   中英

Java Splash Screen scale factor

Java seems to scale the splash screen passed as a jvm switch eg

java -splash:splash_file.png

depending on the size of the monitor.

On the source i can see a reference to some natively calculated scale factor. Does anybody know how this scaling factor is calculated?

I would assume it's calculated by the standard way for graphics which takes an image of a given size in an unbounded "world" (world coordinates), transforms it to a normalized device (think unit square), and then transforms it again to the screen coordinates. The transformations consist of a translation and a scaling of the points.

Given the splash screen's window in the world (the way it should appear without translation or scaling), the normalized (x,y) values are obtained as follows:

The first part is the translation and the second the scale factor. This reduces the image to be contained in a 1 x 1 square so all the (x,y) values are fractional.

To go from the normalized to screen coordinate system the values are calculated as follows:

These operations are typically done efficiently with the help of translation and scaling matrix multiplications. Rotation can also be applied.

This is actually a low-level view of how you could take images, shapes, etc. drawn anyway you like and present them consistently across any sized screens. I'm not sure exactly how it's done in the example you give but it would likely be some variation of this. See the beginning of this presentation for a visual representation.

This value is actually both jdk implementation-dependent and architecture-dependent.

I browsed the OpenJDK code , and for a lot of architectures, it's simply hardcoded to 1.

For example, in the windows bindings, you'll find:

SPLASHEXPORT char*
SplashGetScaledImageName(const char* jarName, const char* fileName,
                       float *scaleFactor)
{
    *scaleFactor = 1;
    return   NULL;
}

The scaleFactor value is then stored into a struct that is accessed via JNI through the _GetScaleFactor method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM