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
+11k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+10.4k Generate Random number with math/rand in Go
+12.5k Golang : Add ASCII art to command line application launching process
+36.1k Golang : How to split or chunking a file to smaller pieces?
+11.8k Golang : Convert decimal number(integer) to IPv4 address
+10.9k Golang : Fix go.exe is not compatible with the version of Windows you're running
+6.4k Golang : Totalize or add-up an array or slice example
+21.9k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+25.3k Golang : convert rune to integer value
+15.6k Golang : How to login and logout with JWT example
+19k Golang : Calculate entire request body length during run time
+12.9k Golang : Calculate elapsed years or months since a date