Golang : Detect number of active displays and the display's resolution
There are times when we need to find out the number of active displays and their resolution. The following code is a simple program that utilized the kbinani/screenshot
package to get the active screens' information.
The information will allow our program to properly capture screenshot or adjust our program output - such as maximizing(fullscreen) to the entire display.
Here you go!
package main
import (
"fmt"
"github.com/kbinani/screenshot"
)
func main() {
n := screenshot.NumActiveDisplays()
fmt.Println("Number of active monitor(s) : ", n)
for i := 0; i < n; i++ {
bounds := screenshot.GetDisplayBounds(i)
x := bounds.Dx()
y := bounds.Dy()
fmt.Printf("Display #%d resolution is %d x %d\n", i, x, y)
}
}
Sample output:
Number of active monitor(s) : 2
Display #0 resolution is 1920 x 1080
Display #1 resolution is 1920 x 1080
Reference :
See also : Golang : Qt get screen resolution and display on center example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+3.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+4.6k Golang : Derive cryptographic key from passwords with Argon2
+3.1k Nginx and PageSpeed build from source CentOS example
+4.8k Golang : How to detect if a sentence ends with a punctuation?
+10.8k Golang : Reverse IP address for reverse DNS lookup example
+8.7k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+21.9k Golang : Convert uint value to string type
+8.9k Golang : Removes punctuation or defined delimiter from the user's input
+5.2k Golang : Example of custom handler for Gorilla's Path usage.
+30.5k Golang : Validate IP address
+9.8k Golang : Change date format to yyyy-mm-dd
+9.4k Golang : Simple client-server HMAC authentication without SSL example