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
+17.7k Golang : [json: cannot unmarshal object into Go value of type]
+9.2k Golang : Intercept and compare HTTP response code example
+13.9k Golang : Convert spaces to tabs and back to spaces example
+7.9k Golang : Reverse a string with unicode
+15.7k Golang : Get checkbox or extract multipart form data value example
+8.5k Golang : Ackermann function example
+9.4k Golang : Play .WAV file from command line
+19.4k Golang : How to count the number of repeated characters in a string?
+13.5k Golang : Verify token from Google Authenticator App
+8.7k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+27.6k Golang : dial tcp: too many colons in address