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 : Fix - does not implement sort.Interface (missing Len method)
+13.4k Golang : Qt progress dialog example
+20.6k Golang : Convert date string to variants of time.Time type examples
+4.9k Golang : Check if a word is countable or not
+9.2k Golang : How to get username from email address
+5.1k PHP : See installed compiled-in-modules
+5.4k PHP : Fix Call to undefined function curl_init() error
+5.3k Golang : Get S3 or CloudFront object or file information
+19k Mac OSX : Homebrew and Golang
+4.8k Unix/Linux : secure copying between servers with SCP command examples
+14.6k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+5.4k PHP : Convert CSV to JSON with YQL example