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.5k Golang : Convert(cast) float to int
+12.5k Golang : unknown escape sequence error
+12k Golang : How to get a user home directory path?
+21k Golang : Read a file into an array or slice example
+4k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+12k Golang : Read from buffered reader until specific number of bytes
+7k Golang : Find relative luminance or color brightness
+18k Mac OSX : Homebrew and Golang
+14.9k Golang : Test floating point numbers not-a-number and infinite example
+17.8k Golang : Check if directory exist and create if does not exist
+9.1k Golang : Convert file unix timestamp to UTC time example
+12.4k Golang : Human readable time elapsed format such as 5 days ago