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
+10.4k Golang : Allow Cross-Origin Resource Sharing request
+7.7k Setting $GOPATH environment variable for Unix/Linux and Windows
+8.2k Golang: Prevent over writing file with md5 hash
+5.6k Unix/Linux : How to test user agents blocked successfully ?
+6.5k Golang : Skip or discard items of non-interest when iterating example
+11.4k Golang : Find age or leap age from date of birth example
+4.5k Javascript : Access JSON data example
+8.2k Golang : Count leading or ending zeros(any item of interest) example
+4.9k Linux : How to set root password in Linux Mint
+11.5k Golang : Gorilla web tool kit secure cookie example
+7.3k Golang : Gorrila set route name and get the current route name
+14.4k Golang : Convert(cast) int to float example