In daily application development, developers need to obtain display-related information to develop subsequent related services, such as screencasting, etc. Based on this demand, EdgerOS provides the Display module to facilitate developers to easily obtain display-related information during application development.
It should be noted that this module is only available in EdgerOS 1.8.0 and above, and requires display permissions to be used.
①Introduce modules:
constDisplay=require('display');
② Instantiation:
new Display(channel)
channel {Integer} displays device information channel identification number
Returns: {Object} Display object
const display = new Display(0);
③ Display list
Display.list()
Returns: {Array} A collection of legal display device information channel identification numbers
console.log(Display.list());// [0:0]
Gets a valid display channel identification number.
④ Equipment information
display.info():Returns: {Object} Display device information
Obtain relevant information about the display device, which can include the following content;
width {Integer} horizontal pixel width
-high {Integer} vertical pixel width
-color {Integer} color depth bits
-linked {Boolean} Whether the monitor is connected
-busy {Boolean} whether it is occupied
const info = display.info();if(info.linked){
console.log(info.width,'X', info.high);}
2. Example
Assuming we have similar needs for screencasting, we can use the Display module to obtain relevant information about the display device. This example is to cast advertising images to the display device. In this example, the Display module is first used to obtain the resolution information of the display device, and the ImageCodec module mentioned above is used to recode the image, and the resolution size of the advertising image is modified to be consistent with the resolution of the display device. , and finally used the previewFormat method of the MediaDecoder module to cast the modified image to the display device.
We can use the Display module for different business development in different scenarios. Screencasting is only part of the purpose. As long as you need to obtain information about display devices, you can consider using the Display module.